How can I create a new application pool in a Web Setup Project?

Grzenio picture Grzenio · Mar 18, 2009 · Viewed 15.1k times · Source

I need to deploy my web service. It needs to run in a separate application pool in IIS with its own credentials.

Is it possible to do this by using a Web Setup Project in VS 2008?

By default, I seem to only be able to choose an existing application pool.

Answer

Faiyaz Khan picture Faiyaz Khan · Apr 21, 2009

Check out this post http://forums.iis.net/t/1061734.aspx, it will give some rough idea about Microsoft.Web.Administration dll.

I have not studied the whole concept but I figured how to create new pool and how to attach with new web site / virtual directory.

Creating Application Pool

Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager();
manager.ApplicationPools.Add("NewApplicationPool");
manager.CommitChanges();

Attaching with existing virtual directory

Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];

// defaultSite.Applications will give you the list of 'this' web site reference and all
// virtual directories inside it -- 0 index is web site itself.

Microsoft.Web.Administration.Application oVDir = defaultSite.Applications["/myApp"];            
oVDir.ApplicationPoolName = "NewApplicationPool";
manager.CommitChanges();

This way you can assign application pool to your new website using the custom actions, overriding the commit method of installer class.

If still find yourself struggling, please let me know and I'll try to send the code.

Regards Faiyaz [email protected]