繁体   English   中英

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

[英]How can i get a list of the websites in IIS from within a ASPX page using c#?

我正在尝试使用

    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); 
} 

我不太确定错误是什么,但猜测它可能是安装问题或权限。

对于安装类型问题:

http://blogs.msdn.com/b/jpsanders/archive/2009/05/13/iis-7-adsi-error-system-runtime-interopservices-comexception-0x80005000-unknown-error-0x80005000.aspx

对于权限类型问题添加配置的内容,如:

<identity impersonate="true" userName="AdminUserName" password="password" /> 

或者将应用程序池运行的用户上下文更改为具有本地管理员权限的用户上下文可以工作。

此外,IIS:// localhost / W3SVC / 1 / Root的子项将是虚拟目录或文件夹。 网站将是IIS:// localhost / W3SVC。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM