如何在C#中获取IIS 6元数据库属性的数字ID?

| 下面的代码可以正常工作,并且可以读取远程IIS 6服务器元数据库中的所有内容-属性的frikkin数字ID除外。我在“ 0”对象中找不到它们。
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标准。 我从服务器上得到的是这个。 ID在哪里? (顺便说一句,该代码似乎也从上层路径获取了继承的属性。对吗?)
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
    
已邀请:
配置数据库模式标识符没有出现在ADSI API中(这是ѭ5包裹的内容。但是您可以使用配置数据库模式文件作为查找: 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或更高版本,因此您需要添加对
System.Xml.Linq
。 我应该警告一下,如果您要使用IIS6兼容性层在IIS7 +上尝试此操作,则需要将架构文件从IIS6服务器复制到IIS7框中。 此外,您实际上应该使用Managed
Microsoft.Web.Administration
API来收集有关IIS7 +服务器的配置数据。这样做的原因是,并非所有IIS6元数据库对象都映射到IIS7的管理主机配置中。 IIS7中还会有一些属性,因为没有匹配的类型,因此这些属性在IIS6包装器中不可见。 也不能保证IIS的将来版本(例如IIS8)将提供IIS6元数据库兼容性层。 最后,这些ID只是命名属性的数字标识符,即它们并不能唯一地标识配置数据库中的任何特定对象,而这是通过配置数据库路径字符串完成的。 存在元数据ID主要是为了使IIS ABO API受益,该API使用这些ID而不是属性名称。我建议改用字符串属性名称作为标识符,因为如前所述,有一些新的IIS7对象和属性没有这些ID。     

要回复问题请先登录注册