Dixin's Blog

Coding.

Debugging Classic ASP with Modern Visual Studio

Recently I tried to show my Mom some websites I built when I was a kid. Those ASP code, some in VBScript while some in JavaScript, are more than 10 years old. They were running fine in PWS, but now they didn’t run in IIS 8.5. I have no idea what’s the problem. It seems a little debugging has to be done.

Debugging with Visual Studio 2013/2015 and IIS Express

I have Windows 8.1 and Visual Studio 2013 (Later I have Windows 10 and Visual Studio 2015). Surprisingly, I found that IIS Express supports ASP:

In addition to supporting ASP.NET, IIS Express also supports Classic ASP and other file-types and extensions supported by IIS – which also makes it ideal for sites that combine a variety of different technologies.

After searching and trying things around, using Visual Studio and IIS Express seems to be the easiest way to run and debug ASP websites:

  1. Modify IIS Express configuration. Open %USERPROFILE%\Documents\IISExpress\config\applicationhost.config. Under <system.webServer>, find <asp>:
    <asp scriptErrorSentToBrowser="true">
        <cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
        <limits />
    </asp>
    and change it to:
    <asp scriptErrorSentToBrowser="true" enableParentPaths="true" bufferingOn="true" errorsToNTLog="true" appAllowDebugging="true" appAllowClientDebug="true">
        <cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
        <session allowSessionState="true" />
        <limits />
    </asp>
  2. In Visual Studio, add existing website to the solution (or open a website), point to the ASP website folder.
  3. Start the website without debugging (Ctrl+F5).I will explain why.
  4. In Visual Studio, open the “Attach to Process” dialog (Ctrl+Alt+P). Notice the “Attach to” has the default option “Automatic: Native code”
    image_thumb9
  5. Click the “Select…” button, change it to “Script”:
    image_thumb10
  6. Now attach to IIS Express:
    image_thumb11
  7. If IIS Express is running multiple websites, there will be multiple iisexpress.exe processes in the “Available Processes”. The current website’s process ID can be found from the IIS Express site list:
    image_thumb13

Now the website can be debugged in Visual Studio:

image

And Solution Explorer shows the triggered .asp files, and how each .asp file includes other files.

image_thumb15

However, if the website is directly started with debugging (F5), Visual Studio will attach to native code or managed code. We have to start the website then manually attach to script code, as MSDN mentions:

When you debug script, Managed code must not be selected. You cannot debug script and managed code at the same time in Visual Studio 2005.

This is why in Step 4 we do not start website with debugging (F5).

As the second last picture shows, the index.asp has a [dynamic] tag. Visual Studio does not automatically map it to index.asp from the file system. This means, if a breakpoint is set in a *.asp file, it won’t trigger when running the website. You may have to go back and forth between dynamic file and static file. To have the mapping automatically, IIS is needed.

Debugging with Visual Studio 2013/2015 and IIS

Here are the steps:

  1. Open IIS manager, change ASP configurations to enable debugging:
    image_thumb
  2. Run Visual Studio as administrator.
  3. Create an empty web application. In Visual Studio 2015, click File –> New –> Project…, then in the new project dialog, search “ASP.NET Web Application”.  A WebApplication.csproj file and Web.config file will be created in the web application directory.
    image

    image
  4. Merge website folder to Visual Studio web application folder. In Visual Studio, include all website files into the created empty web application.
  5. In web application project’s properties, go to Web tab, choose “Local IIS”, create virtual directory in local IIS for this web application.
  6. In the “Attach to Process” dialog, attach Visual Studio to “Script Code” of IIS process (w3wp.exe).
    image_thumb1
  7. Manually start a browser, input the URI of the created virtual directory. Now the breakpoint set in the static .asp file triggers.

With this approach, the created WebApplication.csproj file and Web.config file pollute the website folder. Instead of web application, If creating/opening website in Visual Studio, it works the same as IIS Express. Web application has to be created so that Visual Studio can map to the static .asp files in file system during debugging.

30 Comments

  • 您好!我是江苏卫视的编导唐菁,最近我们在做以当时社会故事类节目,我们在网上看到了汉字叔叔的相关报道,我我们对于他的故事十分感兴趣,想请问一下您方不方便把他的电话号码给我一下呢?我的号码是18229772295.

  • Great article, thanks for sharing! Comes just in time, as I'm dusting off my classic asp chops now for a big modernization project.

  • Thanks, That makes it much nicer than the alternative. Worked like a charm. I could set breakpoints in the Dynamic Pages under script docs, and also edit the pages out of the dynamic.

  • Thanks good work.

  • Thanks for this wonderful article. I can confidently use Visual Studio 2013 to debug the Classic ASP web application and identify the errors accordingly.

  • hello..hope you can help me here..i don't understand no 5. In web application’s project property, choose “Local IIS”, create a virtual directory for website. i cannot find it.

    i'm using visual studio 2015. please help, thanks a lot

  • @mirai maria

    Sorry for the confusion. I updated the text:
    In web application project’s properties, go to the Web tab, choose “Local IIS”, create virtual directory in local IIS for this web application.

  • Hi. Thanks for the article. I have followed the procedure for both iis express and local iis. But when I run the application my break points are not being hit.

    Could you please assist.

  • @Kingsley make sure you add the breakpoints in the script files and not the websites static files. Once you have navigated to the page you want to debug, attach to iisexpress and in the script all the pages will appear. Set you breakpoint in those.

  • I work on legacy ASP code all the time and this does work very well. In addition to what's being said, if you run IIS (not express),and you create a separate app pool for each website, you can then attach to that process called w3wp.exe. The app pool will be identified when you attach it.

  • @larrybud Thank you for pointing this out!

  • Has anybody run into issues when running through the steps for IIS Express on Windows 10 and Visual Studio 2015? I currently get the Application Debugging is Disabled message. I used to debug with no issues on Windows 8.1 and Visual Studio 2013.

  • I thought that I should circle back and mention that the applicationhost.config file is located under <solution folder>\.vs\config\applicationhost.config in Visual Studio 2015. You also have the option to set <UseGlobalApplicationHostFile> to true in your .csproj if you would like to modify %USERPROFILE%\Documents\IISExpress\config\applicationhost.config.

    I now have all my projects running in Visual Studio 2015 without a hitch. This was a great blog post, and thanks for the help!

  • I've not been able to work
    :(

  • I've not been able to work
    :(

    I'm gettint this error: http://www.axiomax.co/borrar/ErrorDebuggin.png

    Any idea?

    Thanks

  • Sorry but I'm brand new to the old classic ASP world and have been handed an old app to modify. I've got a directory tree of .asp, .htm and .js files to start with and a copy of Visual Studio 2015 running on Win7 as my environment.

    You lost me on step 3 of "Debugging with Visual Studio 2013/2015 and IIS" at "Create an empty web application". In VS2015 File->New gives me options for "Project...", "Web site...", and "Project from existing code..." none of which seem obvious choices for a Classic ASP project and all of which seemed geared only for C# projects using some version of the .NET framework.

    Do I need to install or configure VS differently somehow to get a different option suitable to create "an empty web application" that doesn't have a web.config full of junk that will cause me problems down the line or what are the correct choices I should be picking under the "Project..." or "Web Site..." dialogs?

    All of my files are in c:\src\RP_Mess\referral_partner which is where default.asp exists.

  • Thank you!! It worked.

  • Nice Article. Really works

  • @ TT., did you get it to work? I'm in the same boat as you.. can't find the empty web application they mention here. Really appreciate any help.

  • @Matt Thanks for your reply. I added the screenshots for that.

  • Hi Dixin., Thanks lot., never expected reply for this post this soon. what about the config file, we need to replace that one also right.

    so I created a new wep app as you mention above
    then copied all the files and folders to the project including web.config file
    and then go to IIS and select the virtual directory created -> browse with *:80

    I'm getting this error..

    Classic ASP received an HTTP 500 response when reaching out to the MVC app. This usually means the MVC app's 'web.config' file is malformed or missing a required section. It could also mean any of the product's DLLs is missing, or that IIS's '.NET Trust Level' is not set to 'Full', or that file permissions have not been set up correctly.

    any help?


  • Came back from vacation... any help guys..? :) really appreciate it.. not a ASP guy but suddenly landed in this ASP task...

  • Thank you Dixin, this was a huge help!

    @Matt are you sure you selected the "Empty" template (not MVC) when you created a new ASP.NET Web Application project?

  • Step 4 says "Merge website folder to Visual Studio web application folder. In Visual Studio, include all website files into the created empty web application."

    How do you do that? I can't find any "Merge" function in Visual Studio. Other pages on the web only say how to drag-and-drop one project into another, but here we have 1 empty project and 1 directory that isn't a project. If I just use Windows to copy the site files into the empty project directory, VS doesn't see them, and I can't find any VS function to "include all files" as you said. This step is key to the entire process.

  • It appears this "merge" can be done by first creating the empty project, then using File - Open - Web Site to open the directory with the files, then, still in Visual Studio, dragging & dropping the web site files into the project. If there's another way, I'd be interested to hear about it.

  • I tried with visual studio 2013 but it didn't work for me. As it show no symbols cannot be loaded.

  • Great article. Works perfectly - however one small issue. I am using VS2017 and although the debugger attaches and I can view the variables values (if I add a Watch to them) - I don't get anything when hovering over the variables (as per your screen shot showing you hovering over "Response" object).

    Any ideas?

  • Good post shared i really need this post.

  • Thank you, Dixin!
    Very good article. We have a lot of legacy applications in Classic ASP and it is great to be able to use the new IDEs to debug them.
    I couldn't make it work with the IIS Express solution, it wouldn't stop at the breakpoint. But it works great with the IIS solution!

    Best regards,
    Ludmilla

  • Hi Dixin, amazing stuff you got here. However, I can't get my site to work. Please help. I have followed your instruction until Step 6 of Debugging with Visual Studio 2013/2015 and IIS Express. I can't get it to debug. My error is as follow:

    https://i.imgur.com/HhB58NP.jpg

    My solution explorer looks like this.

    https://i.imgur.com/m68j3MK.jpg

    Please help, is there anything missing? Thank you very much.

Add a Comment

As it will appear on the website

Not displayed

Your website