Today the new version of Visual Studio (version 2013) will be officially launched. With this new version it becomes very easy to remotely debug your Windows Azure Websites.
In order to remotely debug your site you will need to download and install the following:
- Visual Studio 2013 (I used the release candidate of the Premium edition).
- And the Azure SDK 2.2
Here is how you do it
First you need to deploy your site in debug build configuration, otherwise you’re breakpoints won’t be hit.
Next you need to add your Azure subscription to Visual Studio so you can manage your subscription from within Visual Studio 2013.
To add you need to right click on “Windows Azure” in the Server Explorer (Ctrl+W,L) and select “Import Subscriptions…”
A popup will appear.
If you haven’t downloaded your subscription file before, you can download it via the “Download subscription file” (1).
After downloading you can select that file via Browse (2), and click on Import (3).
When the import was successful, you can manage all your Azure services from within Visual Studio.
Now you can see your Web Sites under the Windows Azure node in Server Explorer. Right click on the site that you would like to debug and select Attach Debugger. When this is invoked the remote debugging agent will be started on your web site.
When the debugger is attached ALL the breakpoints from every request to the site will be hit. So don’t use this on a site with a lot of users
To filter the requests from only your IP address you can add a filter to your breakpoint by right clicking on your breakpoint and select “Condition…”.
The following popup will appear.
As you can see in my code above, I assigned the
Request.UserHostAddressip to a local variable
string ip = Request.UserHostAddress;
So now I can add the condition to check if
ip is my IP address. The breakpoint will only be hit if this condition is true.
It would be a lot easier to set the condition to:
Request.UserHostAddress == "220.127.116.11", but that didn’t work… Probably because the debugger doesn’t have the Request object in scope. Do you have a better idea?