我正在运行带有 IIS 8 的 Windows Server 2012。我安装了 IIS 6 元数据库兼容性。我一直在尝试找出如何使用 .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(); …Run Code Online (Sandbox Code Playgroud)