2

下面的代码可以正常工作,并且可以读取远程 IIS 6 服务器的元数据库中的所有内容——除了属性的 frikkin 数字 ID。PropertyValueCollection我在对象中找不到它们。

var site = new DirectoryEntry("IIS://" + tbHost.Text + 
                    "/W3SVC/1", tbUsername.Text, tbPassword.Password);

Console.Write("Site {0}\n", site.Name);

foreach (PropertyValueCollection prop in site.Properties)
{
    Console.Write("    {0} (Type {1})\n", prop.PropertyName, 
                                               prop.Value.GetType());
    foreach (var thingInProp in prop)
    {
        Console.Write("        {0}\n", thingInProp);
    }
}

您可以在下图中看到数字 ID。上面的代码成功读取,例如,LogFilePeriod等于 4,但它无法得到LogFilePeriod属性 ID 是 4003 的事实。我需要这些 ID 来制作符合 OVAL 标准的集合。

在此处输入图像描述

我从服务器得到的是这个。身份证在哪里?(顺便说一句,这段代码似乎也从上层路径继承了属性。对吗?)

Site 1
    LogExtFileFlags (Type System.Int32)
        2199519
    LogFileLocaltimeRollover (Type System.Boolean)
        False
    LogFilePeriod (Type System.Int32)
        4
    LogFileTruncateSize (Type System.Int32)
        20971520
    MaxConnections (Type System.Int32)
        1000
    ServerSize (Type System.Int32)
        1
    ServerState (Type System.Int32)
        2
    Win32Error (Type System.Int32)
        0
    AppPoolId (Type System.String)
        DefaultAppPool
    DefaultDoc (Type System.String)
        Default.htm,Default.asp,index.htm,iisstart.htm
    KeyType (Type System.String)
        IIsWebServer
    ServerComment (Type System.String)
        Default Web Site
    SslCtlIdentifier (Type System.String)
        {E553F318-89D9-4C9F-9C09-91FF12A3BFAF}
    SslCtlStoreName (Type System.String)
        CA
    ServerBindings (Type System.String)
        :80:
    AllowKeepAlive (Type System.Boolean)
        True
    AppAllowClientDebug (Type System.Boolean)
        False
    AppAllowDebugging (Type System.Boolean)
        False
    AspAllowOutOfProcComponents (Type System.Boolean)
        True
    AspAllowSessionState (Type System.Boolean)
        True
    AspAppServiceFlags (Type System.Int32)
        0
    AspBufferingLimit (Type System.Int32)
        4194304
    AspBufferingOn (Type System.Boolean)
        True
    AspCalcLineNumber (Type System.Boolean)
        True
    AspCodepage (Type System.Int32)
        0
    AspEnableApplicationRestart (Type System.Boolean)
        True
    AspEnableAspHtmlFallback (Type System.Boolean)
        False
    AspEnableChunkedEncoding (Type System.Boolean)
        True
    AspEnableParentPaths (Type System.Boolean)
        False
    AspEnableTypelibCache (Type System.Boolean)
        True
    AspErrorsToNTLog (Type System.Boolean)
        False
    AspExceptionCatchEnable (Type System.Boolean)
        True
    AspExecuteInMTA (Type System.Int32)
        0
    AspKeepSessionIDSecure (Type System.Int32)
        0
    AspLCID (Type System.Int32)
        2048
    AspLogErrorRequests (Type System.Boolean)
        True
    AspMaxDiskTemplateCacheFiles (Type System.Int32)
        2000
    AspMaxRequestEntityAllowed (Type System.Int32)
        204800
    AspProcessorThreadMax (Type System.Int32)
        25
    AspQueueConnectionTestTime (Type System.Int32)
        3
    AspQueueTimeout (Type System.Int32)
        -1
    AspRequestQueueMax (Type System.Int32)
        3000
    AspRunOnEndAnonymously (Type System.Boolean)
        True
    AspScriptEngineCacheMax (Type System.Int32)
        250
    AspScriptErrorSentToBrowser (Type System.Boolean)
        True
    AspScriptFileCacheSize (Type System.Int32)
        500
    AspScriptTimeout (Type System.Int32)
        90
    AspSessionMax (Type System.Int32)
        -1
    AspSessionTimeout (Type System.Int32)
        20
    AspTrackThreadingModel (Type System.Boolean)
        False
    AuthFlags (Type System.Int32)
        1
    CacheISAPI (Type System.Boolean)
        True
    CGITimeout (Type System.Int32)
        300
    ConnectionTimeout (Type System.Int32)
        120
    ContentIndexed (Type System.Boolean)
        True
    DirBrowseFlags (Type System.Int32)
        1073741886
    LogType (Type System.Int32)
        1
    PasswordChangeFlags (Type System.Int32)
        6
    AnonymousUserName (Type System.String)
        IUSR_OVAL-IIS6-A
    AnonymousUserPass (Type System.String)
        n;x7u'8(H<8&4h
    AspScriptErrorMessage (Type System.String)
        An error occurred on the server when processing the URL.  Please contact the system administrator.
    AspScriptLanguage (Type System.String)
        VBScript
    LogOdbcDataSource (Type System.String)
        HTTPLOG
    LogOdbcPassword (Type System.String)
        sqllog
    LogOdbcTableName (Type System.String)
        InternetLog
    LogOdbcUserName (Type System.String)
        InternetAdmin
    LogPluginClsid (Type System.String)
        {FF160663-DE82-11CF-BC0A-00AA006111E0}
    AspDiskTemplateCacheDirectory (Type System.String)
        %windir%\system32\inetsrv\ASP Compiled Templates
    LogFileDirectory (Type System.String)
        C:\WINDOWS\system32\LogFiles
    HttpErrors (Type System.Object[])
        400,*,FILE,C:\WINDOWS\help\iisHelp\common\400.htm
        401,1,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm
        401,2,FILE,C:\WINDOWS\help\iisHelp\common\401-2.htm
        401,3,FILE,C:\WINDOWS\help\iisHelp\common\401-3.htm
        401,4,FILE,C:\WINDOWS\help\iisHelp\common\401-4.htm
        401,5,FILE,C:\WINDOWS\help\iisHelp\common\401-5.htm
        401,7,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm
        403,1,FILE,C:\WINDOWS\help\iisHelp\common\403-1.htm
        403,2,FILE,C:\WINDOWS\help\iisHelp\common\403-2.htm
        403,3,FILE,C:\WINDOWS\help\iisHelp\common\403-3.htm
        403,4,FILE,C:\WINDOWS\help\iisHelp\common\403-4.htm
        403,5,FILE,C:\WINDOWS\help\iisHelp\common\403-5.htm
        403,6,FILE,C:\WINDOWS\help\iisHelp\common\403-6.htm
        403,7,FILE,C:\WINDOWS\help\iisHelp\common\403-7.htm
        403,8,FILE,C:\WINDOWS\help\iisHelp\common\403-8.htm
        403,9,FILE,C:\WINDOWS\help\iisHelp\common\403-9.htm
        403,10,FILE,C:\WINDOWS\help\iisHelp\common\403-10.htm
        403,11,FILE,C:\WINDOWS\help\iisHelp\common\403-11.htm
        403,12,FILE,C:\WINDOWS\help\iisHelp\common\403-12.htm
        403,13,FILE,C:\WINDOWS\help\iisHelp\common\403-13.htm
        403,15,FILE,C:\WINDOWS\help\iisHelp\common\403-15.htm
        403,16,FILE,C:\WINDOWS\help\iisHelp\common\403-16.htm
        403,17,FILE,C:\WINDOWS\help\iisHelp\common\403-17.htm
        403,18,FILE,C:\WINDOWS\help\iisHelp\common\403.htm
        403,19,FILE,C:\WINDOWS\help\iisHelp\common\403.htm
        403,20,FILE,C:\WINDOWS\help\iisHelp\common\403-20.htm
        404,*,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm
        404,2,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm
        404,3,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm
        405,*,FILE,C:\WINDOWS\help\iisHelp\common\405.htm
        406,*,FILE,C:\WINDOWS\help\iisHelp\common\406.htm
        407,*,FILE,C:\WINDOWS\help\iisHelp\common\407.htm
        412,*,FILE,C:\WINDOWS\help\iisHelp\common\412.htm
        414,*,FILE,C:\WINDOWS\help\iisHelp\common\414.htm
        415,*,FILE,C:\WINDOWS\help\iisHelp\common\415.htm
        500,12,FILE,C:\WINDOWS\help\iisHelp\common\500-12.htm
        500,13,FILE,C:\WINDOWS\help\iisHelp\common\500-13.htm
        500,15,FILE,C:\WINDOWS\help\iisHelp\common\500-15.htm
        500,16,FILE,C:\WINDOWS\help\iisHelp\common\500.htm
        500,17,FILE,C:\WINDOWS\help\iisHelp\common\500.htm
        500,18,FILE,C:\WINDOWS\help\iisHelp\common\500.htm
        500,19,FILE,C:\WINDOWS\help\iisHelp\common\500.htm
    ScriptMaps (Type System.Object[])
        .asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
        .cer,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
        .cdx,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
        .asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
        .idc,C:\WINDOWS\system32\inetsrv\httpodbc.dll,5,GET,POST
        .shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
        .shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
        .stm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
    MaxBandwidth (Type System.Int32)
        -1
    AdminACL (Type System.__ComObject)
        System.__ComObject
4

1 回答 1

2

元数据库架构标识符不会出现在 ADSI API 中(这是System.DirectoryServices.DirectoryEntry包装。您可以使用元数据库架构文件作为查找:

C:\WINDOWS\system32\inetsrv\MBSchema.xml

这是您的代码(稍作修改以访问我的本地元数据库):

XNamespace ns = "x-urn:microsoft-catalog:MetaData_V7";
XDocument schema = XDocument.Load(@"C:\WINDOWS\system32\inetsrv\MBSchema.xml");

using (DirectoryEntry site = new DirectoryEntry("IIS://Localhost/W3SVC/1"))
{
    foreach (PropertyValueCollection prop in site.Properties)
    {
        var schemaProperty = schema.Descendants(ns + "Property")
                .FirstOrDefault(a => 
                     (string)a.Attribute("InternalName") == prop.PropertyName);

        Console.Write("    {0}[ID:{1}] (Type {2})\n", 
            prop.PropertyName,
            schemaProperty.Attribute("ID"),
            prop.Value.GetType());
        foreach (var thingInProp in prop)
        {
            Console.Write("        {0}\n", thingInProp);
        }
    }
}

我假设您使用的是 .NET Framework 3.5 或更高版本,因此您需要添加对 .NET Framework 的引用 System.Xml.Linq

我应该补充一点,如果您使用 IIS6 兼容层在 IIS7+ 上尝试此操作,那么您需要将架构文件从 IIS6 服务器复制到您的 IIS7 框。

此外,您确实应该使用托管Microsoft.Web.AdministrationAPI 来收集有关 IIS7+ 服务器的配置数据。原因是并非所有 IIS6 元数据库对象都映射到 IIS7 的管理主机配置。此外,IIS7 中的某些属性在 IIS6 包装器中不可见,因为没有匹配的类型。

也不保证 IIS 的未来版本(例如 IIS8)将提供 IIS6 元数据库兼容层。

最后,这些 ID 只是命名属性的数字标识符,即它们不会唯一标识元数据库中的任何特定对象,这是通过元数据库路径字符串完成的。

元数据 ID 的存在主要是为了使用这些 ID 而不是属性名称的 IIS ABO API。我建议使用字符串属性名称作为标识符,因为正如我之前提到的,有新的 IIS7 对象和属性没有这些 ID。

于 2011-04-15T11:59:47.050 回答