Setting up a web project environment in Visual Studio 2010 to allow debugging using both IIS7 and the development Web server

by on Jan.13, 2011, under Knowledge Base, Technology, Tutorials

We have run into an issue recently when importing a number of our legacy web projects into Visual Studio 2010. It seems that some projects don’t provide the options to allow us to run and debug them on the local version of IIS. For some reason, when a project is initially configured in VS2010 it sets a flag that determines whether the project properties page is shown inside the project window (where it will contain the necessary configuration options) or the project properties page is shown as a pop-up dialog window (where it doesn’t contain the options to allow debugging on a local IIS).

Here are the notes you will need when setting up a new project to guarantee that you have access to the required configuration page.

IIS 7 Configuration

The first step is entirely optional, as it is perfectly reasonable to run multiple Web Applications within a singe Web Site, however I prefer having separate Web Sites for different projects (or clients) as this allows me to control individual settings for each of them (for example host and port bindings) without me worrying about breaking a different project.

If you will use “localhost” to access the server, then you will only be able to have one Web Site instance running at a time, but this is rarely an issue, and you can easily run more than one site at a time by using a unique hostname or port for each.

Create the site in IIS Manager:

Create the site in IIS Manager

Where you create the Web Site mostly doesn’t matter, Visual Studio will add your project to the site as a virtual directory and the physical files can exist anywhere on your filesystem.

Add web site settings

Manage Web Site

Once the site has been created, stop any other site that is using port 80, and start the Web site from the actions panel at the right of the window.

Because you want Visual Studio to modify the IIS configuration, you will need to run Visual Studio as Administrator.

Create an empty Web Application

Create a new project in Visual Studio (File > New > Project…).

Create an empty Web Application

Select: Visual C# > Web > ASP.NET Empty Web Application.

If you leave the “Create directory for solution” checkbox selected, then all your project files will end up one directory below the solution file. Personally I don’t mind having the .sln file in the same folder as my project files so I uncheck it.

New Web Project Settings

If you click OK to create the various project files, then immediately compile and run the application you will see that by default Visual Studio has configured the development web server.

Cassini - empty web application

Reconfigure the project to use IIS

Web project properties

Now whilst this is useful for small standalone projects, we would ideally like to be able to switch development to the full version of IIS7, and to do this, we need to perform another couple of steps.

Back in Visual Studio, stop the project and in the Solution Explorer, right-click on the project and select “Properties”.

In the window that appears, select the Web option and scroll down until you can see the Servers section. Change the selection from “Use Visual Studio Development Server” to “Use Local IIS Web server”.

VS2010 - Web Server settings

Click the “Create Virtual Directory” button to complete the IIS configuration. If you see the dialog below then everything has gone as expected and you can now run (and debug) your web application in IIS. You can switch between IIS and Cassini (the development web server) simply by changing the radio button back.

Dialog - Virtual directory successfully created.

Using the same web.config for both IIS and Cassini

Because IIS7 uses a new integrated pipeline, and Cassini uses the classic pipeline, some of the settings in the web.config are not compatible. Whilst it is possible to use two web.config files (and move them in and out of the application directory when you switch webservers), it is much more convenient to use a single web.config with both webservers.

.NET will complain about the legacy settings if you are using the integrated pipeline (which we normally will want to do) unless you have the following included in the system.webServer section in the web.config:

<validation validateIntegratedModeConfiguration="false" />

This line instructs the .NET not to validate any settings it finds in the web.config for the integrated pipeline – this allows you to have settings that only work in classic mode (such as httpHandlers and httpModules co-existing with the handlers and modules sections that are required by IIS7.

:, , , , , , , , ,

1 Comment for this entry

  • mj

    even after adding:

    to the web.config i still get this error:
    HTTP Error 500.21 – Internal Server Error
    Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

    pls. help thx in advance

1 Trackback or Pingback for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!