2

我正在使用下面的代码在我的应用程序的 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);
    }
}

如何更改运行此应用程序池的用户凭据?

4

2 回答 2

6

在您创建的行之后将以下内容添加到您的代码中newpool

DirectoryEntry newpool = 
            apppools.Children.Add(appPoolName, "IIsApplicationPool");
// Add this:
newpool.Properties["AppPoolIdentityType"].Value = 3;
newpool.Properties["WAMUserName"].Value = 
            Environment.MachineName + @"\" + username;
newpool.Properties["WAMUserPass"].Value = password;

您显然还需要添加字符串变量usernamepassword方法CreateAppPool()参数。

如果您还不知道,您需要做的另一件事是确保您的应用程序池用户获得足够的权限来访问 IIS 元数据库、ASP.NET 临时文件夹等。您可以通过运行以下命令来完成此操作:

aspnet_regiis.exe -ga <username>

您可以在文件夹中找到此工具%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727。我通常只是使用System.Diagnostics.Process.

最后,应用程序池用户将需要(至少)对应用程序的 web 文件夹具有读取权限。

于 2009-03-19T15:32:35.470 回答
0
aspnet_regiis.exe -ga <username>

可能不是最好的命令。

您应该将 APPPool 用户添加到 IIS_WPG 组并使用该组授予权限。

于 2009-03-19T17:46:49.547 回答