Tuesday, October 4, 2011

Debugging Classic ASP in IIS7 and VS2010



Debugging Classic ASP in IIS7 and VS2010

04 Oct. 2011 BY Kuldeep Pal
Classic ASPWhy would you ever want to debug a classic ASP application in Visual Studio 2010 and IIS7? Well - legacy code and sites. So how to get it done?
First, make sure your development machine is setup correctly (I am using Windows 7) - Control Panel >> Programs >> Turn Windows Features on or off
  • Under Internet Information Services, enable IIS Management Console, IIS Management Scripts & Tools, and IIS Management Service.
  • Under World Wide Web Services:
    • Application Development Features - enable everything
    • Common HTTP Features - enable Default Document and Static Content
    • Security - enable Basic Authentication, Request Filtering and Windows Authentication
  • Click OK
In IIS, add a website that points to the physical location of your files. I'd recommend using a specific port for running the site - see the example below for creating a site named TestApp running on port 1422 - you'll use http://localhost:1422 to browse to the site. Note that an Application Pool is created with the same name - TestApp.
Next, in IIS Manager Features View, double-click Default Document and ensure the Default.asp is in the list. Backup to the Features View and double-click - ASP icon.
  • Enable Parent Paths - set to True
  • Expand Debugging Properties
    • Enable Client-side Debugging - set to True
    • Enable Server-side Debugging - set to True
    • Send Errors to Browser - set to True
Now go back to IIS Connections and select the Application Pools node, select the Application Pool you created for your site and then select Advance Settings. In Advanced Settings, change the Identity to NetworkService (this makes it easy to set you security next).
Now we need to give the User "Network Service" full permissions on the physical site. Go to Explorer, right-click on the top folder, select Properties >> Security. Add the user NETWORK SERVICE and assing full control.
Finally to Visual Studio 2010 - run Visual Studio as an administrator! Then, open your website - File >> Open Web Site >> File System and select the root folder then click open. Now in Solution Explorer, right-click on the site root and select Property Pages. Under Build, select "No Build", then under Start Options >> Server, select "Use custom server" and enter the base URL with the port number for the site you created earlier: http://localhost:1422 - click OK.
Now run your site - Debug (F5) - either the default page or the page you specified in Properties >> Start Options should launch in a browser now. Go back to Visual Studio 2010 and select Debug >> Attach to Process. At the bottom of the dialog, select bot "Show Processes..." check boxes - then in the "Available Processes" list, scroll to the bottom and select w3wp.exe and then click "Attach". If you get a warning select YES/Continue.
You should now be able to set breakpoints in your code and step through the site.
Ciao and Happy debugging!!!