Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Deploy IIS settings along with your Web Project

2.00/5 (3 votes)
15 Nov 20062 min read 1  
Very simple code to set the authentication method for your IIS virtual directory

Introduction

One of the issues that you need to consider as you plan for how to deploy your ASP.NET applications is how to deploy IIS settings along with your solution. This is a brief example of how to set the Virtual Directory Authentication Settings.

Using the code

Add the following code to the CustomAction class' Install method:

VB
REM *******************************************************
REM Set IIS Virtual Dir Authentication Settings' 

TODO: Search for the server number <---------*
Dim vRoot = GetObject("IIS://LocalHost/W3svc/1/Root/" & _
            Me.Context.Parameters.Item("dir")) 

' Set authentication method for the Virtual Dir

vRoot.AuthBasic = False     ' Unset Basic Authentication
vRoot.Authanonymous = False ' Unset Anonymous Authentication
vRoot.AuthNTLM = True       ' Set Integrated Windows Authentication

' Actually apply it 
vRoot.SetInfo()

Just in case

How to create an installer class:

  1. On the File menu, point to New, and then choose Project.
  2. In the New Project dialog box, select Visual Basic Projects in the Project Type pane, and then choose Class Library in the Templates pane. In the Name box, type IISCustomAction.
  3. Click OK to close the dialog box.
  4. On the Project menu, choose Add New Item.
  5. In the Add New Item dialog box, choose Installer Class. In the Name box, type IISCustomAction.
  6. Click OK to close the dialog box.

How to create a deployment project for your WebProject:

  1. On the File menu, choose Add Project, New Project..
  2. In the Add Project dialog box, select Setup and Deployment Projects in the Project Type pane, and then choose Web Setup Project in the Templates pane. In the Name box, type IIS Virtual Installer.
  3. Click OK to close the dialog box.
  4. In the Properties window, select the ProductName property and type IIS Virtual Installer.
  5. In the File System Editor, select Application Folder. On the Action menu, choose Add, Project Output.
  6. In the Add Project Output Group dialog box, select the primary output for the WebProject project. Click OK to close the dialog box.

How to create a custom action for your Deployment Project:

  1. Right click the IIS Virtual Installer Web Setup project in Solution Explorer. On the View menu, point to Custom Actions.
  2. In the Custom Actions Editor, select the Install node. On the Action menu, choose Add Custom Action.
  3. In the Select item in the project dialog box, double-click the Application Folder.
  4. Select the Primary output from the IISCustomAction(Active) item, then click OK to close the dialog box.
  5. In the Properties window, select the CustomActionData property and type /dir=[TARGETVDIR].
  6. On the Build menu, choose Build DBCustomActionInstaller.

Points of Interest

That's it! It works for me. Of course, this is simple, but maybe I've saved you some time searching for it. Now just think of a bit, to get profit off IIS Admin Objects.

Also check out A C Sharp alternative for Visual Basic GetObject function.

History

  • Nov. 14, 2006 - Initial version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here