c#操作iis创建应用程序池出现异常:无效索引的解决方法
相关代码:
public static string createapppool(string apppoolname, string frameworkversion, string managedpipelinemode)
{
directoryentry rootfolder = new directoryentry("iis://localhost/w3svc/apppools");
try
{
directoryentry apppool = rootfolder.children.add(apppoolname, "iisapplicationpool");
if (apppool.properties.contains("apppoolcommand"))
{
apppool.properties["apppoolcommand"][0] = "1";
}
if (apppool.properties.contains("managedruntimeversion"))
{
apppool.properties["managedruntimeversion"][0] = "v4.0";
}
//以下代码在windowsserver2008版本为6.0的系统上会出现异常:
//无效索引(exception from hresult:0x80070585)
//if (apppool.properties.contains("apppoolidentitytype"))
//{
// apppool.properties["apppoolidentitytype"][0] = "4";
//}
if (apppool.properties.contains("enable32bitapponwin64"))
{
apppool.properties["enable32bitapponwin64"][0] = true;
}
apppool.commitchanges();
return null;
}
catch (system.exception ex)
{
logtofile.save(ex, "createapppool");
return ex.message;
}
}
将相关代码注释以后,未见对web应用程序带来任何影响。
以上就是c#操作iis创建应用程序池出现异常:无效索引的解决方法的详细内容。