如何以编程方式在IIS 8上设置应用程序池标识 [英] How to programmatically set App Pool Identity on IIS 8

查看:82
本文介绍了如何以编程方式在IIS 8上设置应用程序池标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IIS 8运行Windows Server2012.我安装了IIS 6元数据库兼容性.我一直在尝试找出如何使用.Net 4.5更改IIS 8的应用程序池标识-我发现的所有示例都是针对IIS 6和7的.

I'm running Windows Server 2012 with IIS 8. I have IIS 6 Metabase Compatibility installed. I have been trying to figure out how to change the App Pool Identity for IIS 8 with .Net 4.5 - all of the examples I found are for IIS 6 and 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;
        }
    }
}

该代码能够找到应用程序池,但是只要我调用它来设置以下任何一项:

The code is able to find the App Pool, but as soon as I invoke it to set any of the following:

 myAppPool.Invoke("AppPoolIdentityType", new Object[] { 3 });
 myAppPool.Invoke("WAMUserName", new Object[] { domain + @"\" + username });
 myAppPool.Invoke("WAMUserPass", new Object[] { password });

关于内部异常,我得到以下错误:

I get the following error on the inner exception:

值不在预期范围内.

Value does not fall within the expected range.

我不确定我缺少什么,或者与IIS 8有什么不​​同.

I'm not sure what I'm missing, or what is different with IIS 8.

推荐答案

尝试一下(来自

这篇关于如何以编程方式在IIS 8上设置应用程序池标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆