[英]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.