Create a new app pool and assign it to a site subfolder on a remote host, using C# and IIS7
- by Soeren
I have a web site running on IIS7 on a remote server. I would like to do the following:
Create a new subfolder under the root virtual directory.
Create a new app pool.
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