我试图远程读取IIS 7配置数据,特别是默认站点的logExtFileFlags。当我看的applicationHost.config在远程服务器上,我看到有问题的信息:如何从“默认”网站读取logExtFileFlags?
<system.applicationHost>
<sites>
<site name="Default" id="1" serverAutoStart="true">
<logFile logExtFileFlags="Date, Time, ClientIP, UserName, SeverIP, Method, UriStem, URIQuery, HttpStatus, TimeTaken, ServerPort, UserAgent, HttpSubStatus" enabled="true" />
</site>
</sites>
</system.applicationHost>
我试图使用ServerManager的远程读取信息。我已经成功读取了其他参数,但它们位于applicationHost.config文件的system.webServer部分。我的代码设置如下:
ServerManager manager = ServerManager.GetApplicationHostConfiguration();
var allSites = manager.Sites
foreach (Site currentSite in allSites)
{
siteName = currentSite.Name;
// I only have the "Default" site on the server in question but other servers may have more than one.
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites",siteName);
}
最后一行不起作用。事实上,它不会编译。这只是为了让你知道我想要做什么。我也意识到会有额外的行来解析logFile标签。经过进一步的研究,我发现以下几点:
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default");
这看起来就像我想要做的。当我输入时,FindElement不是ConfigurationElement的有效方法。我很困惑这一点。任何帮助将不胜感激。
我也会对如何破译这些标志感兴趣,一旦我可以正确地到达对象。一旦我达到这一点,这可能是显而易见的。
感谢您的帮助。您的解决方案完美运作 –
@TomK - 在这种情况下,您应该接受解决问题的答案。 –