C#IIS 7.5类未注册异常

本文关键字:注册 异常 5类 C#IIS | 更新日期: 2023-09-27 18:05:01

我们刚刚启动了一个新的Web服务器,在创建新的应用程序池时遇到了"class not registered"。我使用下面的代码,但我不知道如何区分未注册的内容。任何想法都会很棒。

谢谢。

string path = "IIS://" + server + "/W3SVC";
        string app_pools_path = path + "/AppPools";
        /error below.
        var app_pools = new DirectoryEntry(app_pools_path);
        foreach (DirectoryEntry app_pool in app_pools.Children)
        {
//do work
}

错误"Class no registered"错误代码:2147221164

C#IIS 7.5类未注册异常

在服务器上打开服务器管理器添加新功能===>Web服务器(IIS(===>管理工具===>IIS 6管理兼容性,然后检查IIS6元数据库兼容性。使用原始连接字符串/路径

string path="IIS://"+服务器+"/W3SVC";string app_pools_path=路径+"/AppPools";

请尝试以下操作:

     private void StopAppPool(string app_Pool , string server)
    {
        try
        {
            ConnectionOptions co = new ConnectionOptions();
            co.Username = "DomainName''UserName";
            co.Password = "UserPassword";
            string appPool = "W3SVC/AppPools/" + app_Pool;
            co.Impersonation = ImpersonationLevel.Impersonate;
            co.Authentication = AuthenticationLevel.PacketPrivacy;
            string objPath = "IISApplicationPool.Name='" + appPool + "'";
            ManagementScope scope = new ManagementScope(@"''" + server + @"'root'MicrosoftIISv2", co);
            using (ManagementObject mc = new ManagementObject(objPath))
            {
                mc.Scope = scope;
                mc.InvokeMethod("Stop", null, null);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.StackTrace);
            Console.WriteLine(e.InnerException);
            Console.WriteLine(e.Data);
        }
       //Console.ReadLine();
    } 

应避免使用DirectoryEntry操作IIS 7及以上版本。这是基于IIS ADSI接口的旧API,

http://msdn.microsoft.com/en-us/library/ms524896(v=vs.90(.aspx

IIS 6兼容性可能会帮助你,

http://blogs.msdn.com/b/narahari/archive/2009/05/13/when-using-directoryservices-to-access-iis-schema-iis6-management-compatibility-pack-needs-to-be-installed-system-runtime-interopservices-comexception-0x80005000.aspx

最好的解决方案(也是强类型的,对C#开发人员来说更方便(是Microsoft.Web.Administration,

http://www.iis.net/learn/manage/scripting/how-to-use-microsoftwebadministration