gpt4 book ai didi

c# - 如何使用 C# 从 ASPX 页面中获取 IIS 中的网站列表?

转载 作者:太空狗 更新时间:2023-10-29 23:41:46 25 4
gpt4 key购买 nike

我正在尝试使用

    DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
foreach (DirectoryEntry de in root.Children)
{
}

但我不断得到

[COMException (0x80005000): Unknown error (0x80005000)]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +557
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_IsContainer() +42
System.DirectoryServices.ChildEnumerator..ctor(DirectoryEntry container) +36
System.DirectoryServices.DirectoryEntries.GetEnumerator() +36
IISVdir.List(String RootWeb) in c:\Development\Testing\App_Code\IISVdir.cs:116
_Default.Page_Load(Object sender, EventArgs e) in c:\Development\Testing\Default.aspx.cs:11
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

最佳答案

在 Windows 7/8 中,转到控制面板/程序和功能/打开或关闭 Windows 功能,然后选中所有项目 来自:Web 管理工具,(包括:IIS 管理服务、II 6 管理兼容性)。

你可以使用代码:

public static void OpenWebsite(string name)
{
DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC");
IEnumerator ie = Services.Children.GetEnumerator();
DirectoryEntry Server = null;
string nombre = "";

while (ie.MoveNext())
{
Server = (DirectoryEntry)ie.Current;
if (Server.SchemaClassName == IIsWebServer)
{
nombre = Server.Properties["ServerComment"][0].ToString();
if (nombre == name)
{
break;
}
}
}

Console.Write(nombre);
}

关于c# - 如何使用 C# 从 ASPX 页面中获取 IIS 中的网站列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5414025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com