























http://blogs.msdn.com/helloworld/archive/2008/10/31/how-to-get-iis-web-sites-information-programmatically.aspx
I needed to get the location of IIS log files on my servers, after doing a quick investigation, I am quite amazed on how much information are exposed via managed code.
This snippet will return the name of the sites and the location of the log files.
foreach (DirectoryEntry Site in new DirectoryEntry("IIS://" + System.Environment.MachineName + "/w3svc").Children)
if (String.Compare(Site.SchemaClassName, "IIsWebServer", StringComparison.OrdinalIgnoreCase) == 0)
Console.WriteLine(Site.Properties["ServerComment"].Value.ToString() + " == " + Site.Properties["LogFileDirectory"].Value.ToString());
To get more information about what fields and method you can access, please refer to this MSDN doc: http://msdn.microsoft.com/en-us/library/ms524487.aspx.
Just remember, in Vista/Windows Server 2008, you will need to run that code with elevated privilege.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。