使用 C# 和 IIS7 创建新的应用程序池并将其分配到远程主机上的站点子文件夹

发布于 2024-10-19 08:33:51 字数 971 浏览 9 评论 0原文

我有一个在远程服务器上的 IIS7 上运行的网站。我想执行以下操作:

  1. 在根虚拟目录下创建一个新的子文件夹。
  2. 创建一个新的应用程序池。
  3. 将此新的应用程序池添加到新的子文件夹

通常,我会在 IIS 中手动执行此操作,首先创建应用程序池,然后右键单击子文件夹并选择“添加应用程序”,但我需要在 C# 中以编程方式执行此操作。我已经设法使上述第 1 点和第 2 点起作用,但我找不到将应用程序添加到子文件夹的方法。

这是我迄今为止为 1 和 2 使用的代码:

ServerManager mgr = new ServerManager();
    ApplicationPool myAppPool = mgr.ApplicationPools.Add("MyAppPool");
    myAppPool.AutoStart = true;
    myAppPool.Cpu.Action = ProcessorAction.KillW3wp;
    myAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
    myAppPool.ManagedRuntimeVersion = "V4.0";
    myAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
    mgr.CommitChanges();


    if (!Directory.Exists(@"D:\webroot\TestSite\NytSite"))
    {
        Directory.CreateDirectory(@"D:\webroot\TestSite\NytSite");
    }

所以,我需要将“MyAppPool”添加到“NytSite”文件夹中...

这是否是执行此操作的正确方法?

那里有什么经验吗?

谢谢

I have a web site running on IIS7 on a remote server. I would like to do the following:

  1. Create a new subfolder under the root virtual directory.
  2. Create a new app pool.
  3. Add this new app pool to the new subfolder

Normally, I would do this manually in IIS by first creating the app pool, and then right-clicking the sub folder an choose "add application", but I need to do this programmatically in C#. I've managed to make the above points 1 and 2 work, but I can't find the way to adding the application to the sub folder.

This is the code I have used so far for 1 and 2:

ServerManager mgr = new ServerManager();
    ApplicationPool myAppPool = mgr.ApplicationPools.Add("MyAppPool");
    myAppPool.AutoStart = true;
    myAppPool.Cpu.Action = ProcessorAction.KillW3wp;
    myAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
    myAppPool.ManagedRuntimeVersion = "V4.0";
    myAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
    mgr.CommitChanges();


    if (!Directory.Exists(@"D:\webroot\TestSite\NytSite"))
    {
        Directory.CreateDirectory(@"D:\webroot\TestSite\NytSite");
    }

So, I need to add "MyAppPool" to the "NytSite" folder...

Is this even the correct way to do this?

Any experiences out there?

Thnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉梦枕江山 2024-10-26 08:33:51

您需要创建一个新的应用程序来分配应用程序池,因此您可以这样做:

        if (!Directory.Exists(@"C:\inetpub\wwwroot\JohnSite"))
        {
            Directory.CreateDirectory(@"C:\inetpub\wwwroot\JohnSite");
        }

        // Add to my default site
        var app = mgr.Sites[0].Applications.Add(@"/JohnSite", @"C:\inetpub\wwwroot\JohnSite");
        app.ApplicationPoolName = "MyAppPool";

        mgr.CommitChanges();

You need to create a new Application to assign an application pool, so you can do this:

        if (!Directory.Exists(@"C:\inetpub\wwwroot\JohnSite"))
        {
            Directory.CreateDirectory(@"C:\inetpub\wwwroot\JohnSite");
        }

        // Add to my default site
        var app = mgr.Sites[0].Applications.Add(@"/JohnSite", @"C:\inetpub\wwwroot\JohnSite");
        app.ApplicationPoolName = "MyAppPool";

        mgr.CommitChanges();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文