How to run/debug Visual Studio 2010 websites in IIS 7 instead of the default (Cassini) development web server

No Comments

Written by Luis Miguel – Originally published on May 25, 2011

Synopsis:

When you create an ASP .NET 4 website in Visual Studio 2010 and do not modify any of its default settings as you run or debug this website from the IDE it starts and uses a special web server called Cassini, it does not run in the full blown, professional grade Windows web server (IIS 7)

Microsoft had many reasons to ship this special web server and have it run by default when Visual Studio and Visual Web Developer start a debug session on a project, but I do see a couple of issues with this:

1st – In the real world applications use IIS 7 not Cassinni, so I want to run/debug/test in IIS 7 not Cassini

2nd – Cassini is only available while IDE is running, and it shuts down when you close Visual Studio. I want to be able to use the website and test it at any time, directly from any local browser or remotely from other workstations over the network, without having to keep a Visual Web Developer session open.

These two requirements seem very basic, I don’t feel comfortable testing a project that eventually will be deployed to production unless the site is proven to run stably on the web server that will be hosting it permanently, and I need the flexibility of an always up web server.

So, after a bit of research and some trial and error experimenting, I found the procedure listed below will satisfy this need.

1 – Create a file system folder (c:\websites\mysite
2 – Create a website in IIS 7 that points to the folder you created in step 1
3 – Create an ASP .NET 4.0 website project in Visual Studio 2010 and use the folder you created in step 1 as the target folder
4 – Save the project
5 – Modify the URL in Website Start…

From now on in order to run the website from the IDE in debug mode you need to open Visual Studio with the command “Run as Administrator”

Or use the menu Debug – Attach to Process

6 – Debug the project in Visual Studio 2010 or try to browse the site in a browser window

If you receive the error message “Unrecognized attribute ‘targetFramework’”, make sure the application pool for the website “mysite” in ISS 7 is set to support the 4.0 .NET Framework

Follow the next steps if you want to go a bit further and test the data access layer

  1. Add a database connection to your project
  2. Add a database control to the page Default.aspx
  3. Save the project
  4. Debug the project in Visual Studio 2010 or try to browse the site in a browser window

When I built the test for the data access layer on the 2nd environment [specs listed below] I ran into this problem:

‘Handler “PageHandlerFactory-Integrated” has a bad module “ManagePipelineHandler” in its module list’

To resolve it I ran the command
c:\windows\Microsoft.NET\Framework\v4.030319\aspnet_regiis.exe –i

There are some explanations about this issue on the internet and even more than one way (command) to resolve it. I know I installed SQL Server 2008 Service Pack 1 after the .NET framework and ASP .NET 4 so that could have been the problem but the command listed above took care of it in a couple of seconds.

This procedure applies to “WEBSITE” projects, if you created an ASP .NET “application” project, most of this work can be very easily done thru the menu.

Technologies used:

1st Environment
- Windows Server 2008 R2 Enterprise 64-bit
- SQL Server 2008 R2 Standard 64-bit
- Internet Information Service (IIS) 7
- Visual Studio Professional 2010

2nd environment
- Windows Server 2008 Standard 32-bit with Service Pack 2
- SQL Server 2008 Standard 32-bit with Service Pack 1
- Internet Information Services (IIS) 7
- Visual Web Developer Express 2010

Comments are closed.

Powered by Netfirms