I have a web site running on IIS7 on a remote server. I would like to do the following:
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
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.