【发布时间】:2015-01-22 20:31:51
【问题描述】:
我正在运行带有 IIS 8 的 Windows Server 2012。我安装了 IIS 6 Metabase Compatibility。我一直在尝试弄清楚如何使用 .Net 4.5 更改 IIS 8 的应用程序池标识 - 我发现的所有示例都是针对 IIS 6 和 7 的。
这是我所拥有的:
public class InternetInformationServices
{
public void SetApplicationPoolIdentity(string appPoolName, string domain, string username, string password)
{
try
{
string metabasePath = "IIS://Localhost/W3SVC/AppPools";
DirectoryEntry myAppPool;
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
myAppPool = apppools.Children.Find(appPoolName, "IIsApplicationPool");
myAppPool.Invoke("AppPoolIdentityType", new Object[] { 3 });
myAppPool.Invoke("WAMUserName", new Object[] { domain + @"\" + username });
myAppPool.Invoke("WAMUserPass", new Object[] { password });
myAppPool.Invoke("SetInfo", null);
myAppPool.CommitChanges();
}
catch (Exception)
{
throw;
}
}
}
代码能够找到应用程序池,但只要我调用它来设置以下任何一项:
myAppPool.Invoke("AppPoolIdentityType", new Object[] { 3 });
myAppPool.Invoke("WAMUserName", new Object[] { domain + @"\" + username });
myAppPool.Invoke("WAMUserPass", new Object[] { password });
我在内部异常中收到以下错误:
值不在预期范围内。
我不确定我缺少什么,或者 IIS 8 有什么不同。
【问题讨论】:
-
你应该摆脱那个 try/catch 块。它没有任何好处
标签: c# .net iis iis-8 application-pool