简体   繁体   English

ServerManager,正在创建应用程序池,未设置身份

[英]ServerManager, Creating application pool, identity not set

I'm trying to create application pool using the ServerManager class.我正在尝试使用ServerManager类创建应用程序池。 This is my code:这是我的代码:

using (ServerManager serverManager = new ServerManager())  {
   if (!serverManager.ApplicationPools.Any(p => p.Name == poolName))  {
     ApplicationPool newPool = serverManager.ApplicationPools.Add(poolName);
     newPool.ManagedRuntimeVersion = "v4.0";
     newPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
     newPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
     newPool.ProcessModel.UserName = user;
     newPool.ProcessModel.Password = pass;
     serverManager.CommitChanges();
   }
}

The application pool gets created, but no identity is set for it - the identity column in the application pools table in IIS Manager is blank.应用程序池已创建,但未为其设置标识 - IIS 管理器中应用程序池表中的标识列为空。 What am i doing wrong?我究竟做错了什么?

User is in the form of domain\\username, and the credentials passed are correct (another part of code checks for those).用户是域\\用户名的形式,并且传递的凭据是正确的(另一部分代码检查这些)。

Take a look to this code.看看这段代码。 It is working for me:它对我有用:

public static ApplicationPool GetOrCreateApplicationPool(ServerManager serverManager, string applicationPoolName, string userName, SecureString password)
{
    if (!serverManager.ApplicationPools.Any(p => p.Name.Equals(applicationPoolName)))
    {
        ApplicationPool appPool = serverManager.ApplicationPools.CreateElement();
        appPool.Name = applicationPoolName;
        appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
        appPool.ManagedRuntimeVersion = "v4.0";

        if(password != null)
        {
            if (!(string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password.ToPlainTextString())))
            {
                appPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
                appPool.ProcessModel.UserName = userName;
                appPool.ProcessModel.Password = password.ToPlainTextString();
            }
        }                

        serverManager.ApplicationPools.Add(appPool);
        serverManager.CommitChanges();
    }

    return serverManager.ApplicationPools.First(p => p.Name.Equals(applicationPoolName));
}

Of course there are some additional methods such extensions that might cause this piece of code is not able to run but the idea is there and this is currently running on my application.当然,还有一些额外的方法,例如扩展,可能会导致这段代码无法运行,但想法就在那里,目前正在我的应用程序上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序池标识更改 - application pool identity change 在IIS 7中以编程方式为自定义身份应用程序池设置用户帐户 - Programmatically set up user account for custom identity application pool in IIS 7 如何正确设置IIS 7应用程序池标识? - How to set up IIS 7 application pool identity correctly? 使用 servermanager web 设置项目将应用程序池设置为特定的 iis 应用程序 - Setting application pool to a specific iis application using servermanager web setup project 以编程方式获取应用程序池标识 - Get the Application Pool Identity programmatically 如何将IIS应用程序池标识用户区域设置为ApplicationPoolIdentity时,如何设置它 - How do you set the IIS Application Pool Identity User Locale when it's set to ApplicationPoolIdentity ServerManager 在 c# Winforms 应用程序中因 0x80040154 而失败,在 IIS 中创建简单的 Web 应用程序 - ServerManager fails with 0x80040154 in c# Winforms app creating simple web application in IIS 使用ServerManager类设置网站端口 - Set website port with ServerManager class 由于应用程序池标识,连接到TfsTeamProjectCollection失败 - Connecting to TfsTeamProjectCollection fails due to Application Pool Identity HttpWebRequest、TLS 和应用程序池服务标识 - HttpWebRequest, TLS and application pool service identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM