views:

2881

answers:

2

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.

+2  A: 

I've been down this road before and unfortunately you'll need to create the application pool manually or write a Custom Action to manage this for you.

Further to Grzenio's question in the comments below:

"Could you give me a hint where to start looking for the code/helper classes? And do you keep your project a Web Setup Project, or just use the standard application setup project?"

I added a new project called InstallHelper to the solution containing the setup project. In that project I created a class called InstallActions which derives from:

System.Configuration.Install.Installer (MSDN).

There are four methods you can override on the Installer base class to allow you to specify custom actions depending on whether you're in the Install, Commit, Uninstall or Rollback phases when the installer is running.

I also added a number of text box dialogues to the setup project user interface. Input and state captured from these dialogues is passed to your custom install action via a dictionary. i.e.:

using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;

namespace InstallHelper
{
    [RunInstaller(true)]
    public partial class PostInstallActions : Installer
    {   
     public override void Install(IDictionary state)
     {
      base.Install(state);
      // Do my custom install actions
     }

     public override void Commit(IDictionary state)
     {
      base.Commit(state);
      // Do my custom commit actions
     }

     public override void Uninstall(IDictionary state)
     {
      base.Uninstall(state);
      // Do my custom uninstall actions
     }
     public override void Rollback(IDictionary state)
     {
      base.Uninstall(state);
      // Do my custom rollback actions
     }
    }
}

To add your custom action project to the setup project, open the Custom Actions viewer/editor and specify the output from the InstallHelper project.

That's the basics and should get you started. The Web Setup Project also supports custom actions and additional user input dialogue boxes, so you may wish to re-use your existing project, in addition to a custom action.

HTH
Kev

Kev
I use Custom Actions to do this in .net 2.0
Ken Browning
Cheers for the answer. Could you give me a hint where to start looking for the code/helper classes? And do you keep your project a Web Setup Project, or just use the standard application setup project?
Grzenio
I initially looked at the Web Setup Project but chose to use the standard setup project instead because my requirements also included having to install a windows service and create the web site.
Kev
+2  A: 

Hi there,

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 direcroty

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]