如何从 C# 更改 IIS 中应用程序池的用户名/密码?
我使用下面的代码在应用程序的 Installer 类中创建一个新的应用程序池:
private static void CreateAppPool(string serverName, string appPoolName)
{
// metabasePath is of the form "IIS://<servername>/W3SVC/AppPools"
// for example "IIS://localhost/W3SVC/AppPools"
// appPoolName is of the form "<name>", for example, "MyAppPool"
string metabasePath = string.Format("IIS://{0}/W3SVC/AppPools", serverName);
Console.WriteLine("\nCreating application pool named {0}/{1}:", metabasePath, appPoolName);
try
{
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
DirectoryEntry newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
newpool.CommitChanges();
Console.WriteLine("AppPool created.");
}
catch (Exception ex)
{
Console.WriteLine("Failed in CreateAppPool with the following exception: \n{0}", ex.Message);
}
}
如何更改运行此应用程序池的用户凭据?
I am using the code below to create a new application pool in the Installer class of my application:
private static void CreateAppPool(string serverName, string appPoolName)
{
// metabasePath is of the form "IIS://<servername>/W3SVC/AppPools"
// for example "IIS://localhost/W3SVC/AppPools"
// appPoolName is of the form "<name>", for example, "MyAppPool"
string metabasePath = string.Format("IIS://{0}/W3SVC/AppPools", serverName);
Console.WriteLine("\nCreating application pool named {0}/{1}:", metabasePath, appPoolName);
try
{
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
DirectoryEntry newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
newpool.CommitChanges();
Console.WriteLine("AppPool created.");
}
catch (Exception ex)
{
Console.WriteLine("Failed in CreateAppPool with the following exception: \n{0}", ex.Message);
}
}
How can I change the user credentials under which this application pool is running?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将以下内容添加到创建
newpool
的代码行之后:显然,您需要将字符串变量
username
和password
添加到您的CreateAppPool()
方法参数也是如此。如果您还不知道,您需要做的另一件事是确保您的应用程序池用户获得足够的权限来访问 IIS 元数据库、ASP.NET 临时文件夹等。您可以通过运行以下命令来完成此操作:
您可以在文件夹
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727
中找到此工具。 我通常只是使用 System.Diagnostics.Process 进行处理。最后,应用程序池用户(至少)需要对应用程序的 Web 文件夹的读取权限。
Add the following to your code just after the line where you create
newpool
:You'll obviously need to add the string variables
username
andpassword
to yourCreateAppPool()
method parameters as well.Another thing you need to do, if you weren't already aware, is make sure your application pool user gets sufficient rights to access the IIS metabase, ASP.NET temp folders etc. You can do this by running the following command:
You can find this tool in the folder
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727
. I usually just shell out usingSystem.Diagnostics.Process
.And finally, the application pool user will need (at least) read rights on the web folder for the app.
可能不是最好使用的命令。
您应该将 APPPool 用户添加到 IIS_WPG 组并授予使用该组的权限。
Is probably not the best command to use.
You should add the APPPool user to the IIS_WPG group and grant rights using that group.