When creating a new IIS web site, how can I add it to an existing application pool?
Posted
by Ian Robinson
on Stack Overflow
See other posts from Stack Overflow
or by Ian Robinson
Published on 2010-03-12T17:10:10Z
Indexed on
2010/03/12
17:37 UTC
Read the original article
Hit count: 490
I have successfully automated the process of creating a new IIS website, however the code I've written doesn't care about application pools, it just gets added to DefaultAppPool. However I'd like to add this newly created site to an existing application pool.
Here is the code I'm using to create the new website.
var w3Svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", webserver));
var newsite = new object[] { serverComment, new object[] { serverBindings }, homeDirectory };
var websiteId = w3Svc.Invoke("CreateNewSite", newsite);
site.Invoke("Start", null);
site.CommitChanges();
<update>
Although this is not directly related to the question, here are some sample values being used above. This might help someone understand exactly what the code above is doing more easily.
- webServer: "localhost"
- serverComment: "testing.dev"
- serverBindings: ":80:testing.dev"
- homeDirectory: "c:\inetpub\wwwroot\testing\"
</update>
If I know the name of the application pool that I'd like this web site to be in, how can I find it and add this site to it?
© Stack Overflow or respective owner