Attaching Visual Studio Debugger to ASP.NET

I’m pretty sure there are bunch of people who also having problem that whenever they debug their ASP.NET project, the page run, and Visual Studio can’t debug it.

Actually one can attach the process to the development web server manually by go to Debug –> Attach to Process (may vary from version or edition) and select the development web server instance.

I found a single click method to get the job done. Using Macro. In Macro Explorer, create a new macro and new module, and using these codes:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module Module1

Public Sub AttachProcess()
    Dim process As EnvDTE.Process
    
    For Each process In DTE.Debugger.LocalProcesses
        If (System.IO.Path.GetFileName(process.Name).ToLower() = "webdev.webserver.exe") Then
            process.Attach()
            Exit Sub
        End If
    Next

    MsgBox("No Development Server Found")
End Sub

End Module

To make the life easy to run the macro, go to Tools –> Customize –> Keyboard and locate the macro and assign to a new shortcut key. That’s it, whenever the web project is running, press they shortcut key and the debugger will be running. But due to the nature of the codes, it will attach to the first development web server found, it might be able tweaked to become more flexible.

 

Leave a Reply

Your email address will not be published. Required fields are marked *