我们刚刚启动了一个新的Web服务器,并且在创建新的应用程序池时遇到了“未注册的类”。我正在使用下面的代码,但我不知道如何区分未注册的内容。任何想法都会很棒。
感谢。
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
答案 0 :(得分:1)
在服务器上打开服务器管理器 添加新功能==> Web服务器(IIS)==>管理工具==> IIS 6管理兼容性然后检查IIS6元数据库兼容性。使用原始连接字符串/路径
string path =" IIS://" + server +" / W3SVC&#34 ;; string app_pools_path = path +" / AppPools";
答案 1 :(得分:0)
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();
}
答案 2 :(得分:0)
您应该避免使用DirectoryEntry
来操纵IIS 7及更高版本。这是基于IIS ADSI接口的旧API,
http://msdn.microsoft.com/en-us/library/ms524896(v=vs.90).aspx
IIS 6兼容性可能会帮助你,
最佳解决方案(对于C#开发人员而言也是强类型且更方便)是Microsoft.Web.Administration,
http://www.iis.net/learn/manage/scripting/how-to-use-microsoftwebadministration