如何解决如何在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,C:\\WINDOWS\\help\\iisHelp\\common\\401-1.htm
401,2,C:\\WINDOWS\\help\\iisHelp\\common\\401-2.htm
401,3,C:\\WINDOWS\\help\\iisHelp\\common\\401-3.htm
401,4,C:\\WINDOWS\\help\\iisHelp\\common\\401-4.htm
401,5,C:\\WINDOWS\\help\\iisHelp\\common\\401-5.htm
401,7,C:\\WINDOWS\\help\\iisHelp\\common\\401-1.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-1.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-2.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-3.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-4.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-5.htm
403,6,C:\\WINDOWS\\help\\iisHelp\\common\\403-6.htm
403,C:\\WINDOWS\\help\\iisHelp\\common\\403-7.htm
403,8,C:\\WINDOWS\\help\\iisHelp\\common\\403-8.htm
403,9,C:\\WINDOWS\\help\\iisHelp\\common\\403-9.htm
403,10,C:\\WINDOWS\\help\\iisHelp\\common\\403-10.htm
403,11,C:\\WINDOWS\\help\\iisHelp\\common\\403-11.htm
403,12,C:\\WINDOWS\\help\\iisHelp\\common\\403-12.htm
403,13,C:\\WINDOWS\\help\\iisHelp\\common\\403-13.htm
403,15,C:\\WINDOWS\\help\\iisHelp\\common\\403-15.htm
403,16,C:\\WINDOWS\\help\\iisHelp\\common\\403-16.htm
403,17,C:\\WINDOWS\\help\\iisHelp\\common\\403-17.htm
403,18,C:\\WINDOWS\\help\\iisHelp\\common\\403.htm
403,19,20,C:\\WINDOWS\\help\\iisHelp\\common\\403-20.htm
404,C:\\WINDOWS\\help\\iisHelp\\common\\404b.htm
404,C:\\WINDOWS\\help\\iisHelp\\common\\404b.htm
405,C:\\WINDOWS\\help\\iisHelp\\common\\405.htm
406,C:\\WINDOWS\\help\\iisHelp\\common\\406.htm
407,C:\\WINDOWS\\help\\iisHelp\\common\\407.htm
412,C:\\WINDOWS\\help\\iisHelp\\common\\412.htm
414,C:\\WINDOWS\\help\\iisHelp\\common\\414.htm
415,C:\\WINDOWS\\help\\iisHelp\\common\\415.htm
500,C:\\WINDOWS\\help\\iisHelp\\common\\500-12.htm
500,C:\\WINDOWS\\help\\iisHelp\\common\\500-13.htm
500,C:\\WINDOWS\\help\\iisHelp\\common\\500-15.htm
500,C:\\WINDOWS\\help\\iisHelp\\common\\500.htm
500,C:\\WINDOWS\\help\\iisHelp\\common\\500.htm
ScriptMaps (Type System.Object[])
.asp,C:\\WINDOWS\\system32\\inetsrv\\asp.dll,GET,HEAD,POST,TRACE
.cer,TRACE
.cdx,TRACE
.asa,TRACE
.idc,C:\\WINDOWS\\system32\\inetsrv\\httpodbc.dll,POST
.shtm,C:\\WINDOWS\\system32\\inetsrv\\ssinc.dll,POST
.shtml,POST
.stm,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框中。
此外,您实际上应该使用ManagedMicrosoft.Web.Administration
API来收集有关IIS7 +服务器的配置数据。这样做的原因是,并非所有IIS6元数据库对象都映射到IIS7的管理主机配置中。 IIS7中还会有一些属性,因为没有匹配的类型,因此这些属性在IIS6包装器中不可见。
也不能保证IIS的将来版本(例如IIS8)将提供IIS6元数据库兼容性层。
最后,这些ID只是命名属性的数字标识符,即它们并不能唯一地标识配置数据库中的任何特定对象,而这是通过配置数据库路径字符串完成的。
存在元数据ID主要是为了使IIS ABO API受益,该API使用这些ID而不是属性名称。我建议改用字符串属性名称作为标识符,因为如前所述,有一些新的IIS7对象和属性没有这些ID。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。