Debugging by attaching to ASP.NET process


Edit: This is also applicable for desktop apps or dlls. Just attach to the name of the “exe” process or in the case of dlls, just attach to the name of the “exe” process that is using the dll.

I just found out about this trick a week ago. Saves time when debugging an ASP.NET web application. Another way to debug an ASP.NET application in Visual Studio is to use the Attach to Process function available in the Debug menu. This would, like the name says, attach to and debug a currently running process in your machine that is outside of Visual Studio. To debug an ASP.NET application, it should first be setup as a local website in your machine (i.e. http://localhost/mywebsite). Browse to that website using your favorite browser. Open your solution in Visual Studio if you haven’t opened it yet. Put in breakpoints anywhere you need them. Click on Debug > Attach to Process and find the ASP.NET process running in your machine. The process name should be aspnet_wp.exe in Windows XP. Click the Attach button and you should be in debug mode without the Visual Studio compiling anything. That’s it. Visual Studio will break/pause if you hit a breakpoint while browsing through your site in the browser.

I find this trick relatively faster than using the default Start Debugging function. This is especially useful if you have multiple projects in your solution which is the case in an AspDotNetStorefront project. Remember though that by default, Visual Studio will only be able to debug a process if the code version is the same as the website that you’re debugging. So don’t forget to compile referenced projects (dll) that changed before debugging.

Another way to save time is configuring your build process in the Configuration Manager of your solution’s property page. But I like attaching to ASP.NET process better cause it’s more straightforward and flexible.More info about attaching to a running process can be found here.