下面的代码工作正常,可以读取远程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
答案 0 :(得分: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或更高版本,因此您需要添加引用
System.Xml.Linq
。
我应该补充一点,如果您在IIS7 +上使用IIS6兼容层尝试此操作,那么您需要将架构文件从IIS6服务器复制到IIS7盒。
此外,您应该使用托管Microsoft.Web.Administration
API来收集有关IIS7 +服务器的配置数据。原因是并非所有IIS6 Metabase对象都映射到IIS7的管理主机配置。 IIS7中也会有一些属性在IIS6包装器中没有可见性,因为没有匹配的类型。
也无法保证IIS的未来版本(例如IIS8)将提供IIS6元数据库兼容性层。
最后,这些ID只是命名属性的数字标识符,即它们不能唯一地标识元数据库中的任何特定对象,这是通过配置数据库路径字符串完成的。
元数据ID的存在主要是为了IIS ABO API的利益,它使用这些ID而不是属性名称。我建议使用字符串属性名称作为标识符,因为正如我之前提到的那样,有新的IIS7对象和属性没有这些ID。