Create a new app pool and assign it to a site subfolder on a remote host, using C# and IIS7

Posted by Soeren on Stack Overflow See other posts from Stack Overflow or by Soeren
Published on 2011-02-28T15:24:04Z Indexed on 2011/02/28 15:24 UTC
Read the original article Hit count: 255

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about iis7