我需要使用Web管理獲取IIS7上站點ID和狀態的幫助。我有這個代碼如何使用Web管理獲取IIS 7中的站點ID和站點狀態C#
private string getSiteIdByName(string siteName)
{
DirectoryEntry root = getDirectoryEntry("IIS://" + textServer.Text + "/W3SVC");
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IIsWebServer")
{
if (e.Properties["ServerComment"].Value.ToString().Equals(siteName, StringComparison.OrdinalIgnoreCase))
{
return e.Name;
}
}
}
return null;
}
private void showStatus(string siteId)
{
string result = "unknown";
DirectoryEntry root = getDirectoryEntry("IIS://" + textServer.Text + "/W3SVC/" + siteId);
PropertyValueCollection pvc;
pvc = root.Properties["ServerState"];
if (pvc.Value != null)
result = (pvc.Value.Equals((int)ObjectState.Start) ? "Running" :
pvc.Value.Equals((int)ObjectState.Stop) ? "Stopped" :
pvc.Value.Equals((int)ObjectState.Pause) ? "Paused" :
pvc.Value.ToString());
labelStatus.Text = result + " (" + pvc.Value + ")";
}
但它確實不適合我們的一些服務器。有沒有辦法使用Web管理?任何援助非常感謝。
謝謝!