Partilhar via


Another Cool Way to Remotely Debug Azure Web Sites

When I was working on a project last week I was having some problems getting the debugging experience working correctly between Visual Studio 2013 and my code which was running in an Azure web site. Fortunately a really smart guy that works here, Petr, gave me a set of instructions to get debugging started another way. He said it was posted in a blog article somewhere so with all due deference...I'm posting the steps and a picture or two here because I didn't happen to find it when I was looking, so perhaps the more blog posts on this topic the easier it will be to find. :-) 

The particular issue I hit required me to attach the debugger, but not in the way I have typically seen to to do it, which is by selecting the web site from within the Visual Studio Azure resources list, then choosing the Attach Debugger menu item. In this case, I needed the application to be up and running and already logged in via the browser to the site. So given that, here's how you can attach to any Azure web site. To begin with, first you want to go in and make sure that remote debugging is enabled for the web site. Visual Studio sets this to true when you attach the debugger through it, but it only lasts for 48 hours and then it resets. The same holds true even if you set it manually, so you'll need to go in and check each time before you start debugging. To get there, just go into the Azure management portal, click on your web site, then click on the Configure tab. Scroll most of the way down and you'll see this switch for enabling remote debugging; just set it to "ON".

After you've turned it on and saved your changes you can follow these steps that Petr provided to me to start debugging:

  1. Download the publishing profile for your Azure web site and save it locally, then open it up in Notepad. You'll need to copy some values out of it later.
  2. If you haven't already, open up your browser and navigate to your Azure web site to make sure it's up and running.
  3. In Visual Studio have your project open, the click on Debug...Attach to Process.
  4. Change the Qualifier to yourSiteName.azurewebsites.net and then click the Refresh button. See the picture below if you're unclear what I mean.
  1. After you click the Refresh button you should get an authorization window. For the username type in ".\" and then paste in the userName attribute from the publishing profile. It should be something like $yourSiteName, so you what you type in for the user name should be .\$yourSiteName.
  2. Paste the userPWD attribute in as the password. Visual Studio should then be able to connect to the Azure web site and show you some processes. There may be one or more MSVSMON processes, but only one w3wp.exe process. Attach to that.

That's it. You should be attached to your Azure web site code now and ready to start debugging. Hope this helps someone.