The ability for a developer to be able to affectively debug and step through the source code of a Web Application is essential to being able to troubleshoot and fix many bugs that can occur. This is especially true when troubleshooting some crazy edge case that came about in production where applications meet real users. Remote debugging isn’t a new feature to Visual Studio and IIS, but how can it be done with a Web App hosted in Azure? This article will step through how to both configure the Azure Web App, as well as how to connect the Visual Studio Debugger running on your local machine.
First, before we dig into the technical stuff, let’s outline what the assumptions are. This article assumes you have or know the following…
- You already have an app that you’ve deployed out to an Azure Web App from Visual Studio
- You have a basic understanding of how to debug applications from Visual Studio
- You have a basic understanding of how to navigate the Azure Portal.
Now that we’re clear what you need to have or know to follow the below steps, we can get started.
But… Before we begin, if you would like a video overview of how to Remotely Debug an Azure Web App with full steps that include deployment instructions and other details not included in this article, then I recommend you check out the Opsgility Hands-On Lab: Getting Started with ASP.NET Web Apps in Azure. This hands-on lab includes both a video that goes over everything, as well as a step-by-step guide so you can go through everything in the video yourself. Learn by doing with the Opsgility Labs!
Enable Azure Web App Remote Debugging
Before the Visual Studio Remote Debugger can be attached to the Web App, you must first enable remote debugging for the Azure Web App.
To do this through the Azure Portal, follow these steps:
- Navigate to the Azure Portal
- Within the Azure Portal, navigate to the blade for your Web App and open the “Application Settings” blade.
- Once in the Application Settings, scroll down to locate the “Debugging” settings section.
- Toggle the “Remote debugging” setting to “On”
- Toggle the “Remote Visual Studio version” to the version of Visual Studio you are using. This can be 2012, 2013, or 2015.
- Click “Save”
Set Deployment Credentials
Once you have enabled Remote Debugging for the Azure Web App, the next step is to set the Deployment Credentials. These are the credentials the Visual Studio Debugger will use to authenticate and authorize the connection to the Azure Web App server.
To do this, follow these steps:
- Navigate to the Azure Portal
- Within the Azure Portal, navigate to the blade for your Web App and open the “Deployment credentials” blade.
- Once in the Deployment credentials blade, you need to enter a “Deployment user name”
- Enter a Password
- Click “Save”
FYI, there are a couple things that are worth knowing about the Deployment Credentials:
- The deployment credentials user name is tied to your Microsoft Account or Organization Account you’re logged into the Azure Portal with. This means that once you set it for one Web App, you can use these same credentials to remotely debug any other Azure Web App in all subscriptions your account has access to.
- With the deployment credentials being tied to your account, this makes it so the user name needs to be unique within Azure, not just the individual Subscription.
- These same deployment credentials can also be used to do deployments over FTP as well as Remote Debugging.
Connecting the Visual Studio Debugger
Once the Azure Web App has Remote Debugging turned On and you have set your Deployment Credentials, the Visual Studio Debugger can now be remotely connected to the Azure Web App!
Follow these steps to attach the Visual Studio Debugger to the Azure Web App in order to do Remote Debugging:
- Open the Web Application Solution/Project within Visual Studio
- Open the “Debug” menu, and select “Attach to Process…”
- Within the “Attach to Process” dialog, enter the Domain for the Azure Web App into the “Qualifier” field.
- Click the “Refresh” button in the lower right corner of the dialog to initiate connecting to the remote process.
- When prompted, enter the Deployment Credentials to authenticate with the Azure Web App’s server
- Once authenticated, it may take a few seconds to load the list of processes on the Azure Web App
- Select the “w3wp.exe” Process (this is the IIS process that’s hosting the Web App on the server)
- Click the “Attach” button to attach the Visual Studio Debugger remotely to the Azure Web App
- Set breakpoints and enjoy Remote Debugging and enjoy being able to troubleshoot those pesky bugs that only seem to occur within your Azure Web App hosted environment.
Benefits of Azure Web App Remote Debugging
Being able to step through your source code during execution to affective debug and troubleshoot an issue is a very essential activity (ahem, skill?) for all developers. Sure, the code is written to be bug free, but there’s always some bugs to iron out before passing from QA into Production. Unfortunately, there’s even the unfortunate Production bug from time to time as well. These bugs are what make being able to affecting step through and debug the code so essential.
Debugging locally is a huge help during development, but there’s only so much that can be done with fake, made up Dev/Test data. There always comes times when some weird bug only shows itself with real, Production or QA data and usage scenarios. For these cases it’s essential to be able to debug the specific environment being effected.
Affectively debugging any environment is done by debugging an environment that’s as close in configuration and deployment as the specific environment with the issue to debug. This is a particular debug scenario that is not met by debugging localhost on the development machine. This is the case where remote debugging is needed, and is the specific scenario that is why Azure Web Apps ultimately support Remote Debugging.
By Remotely Debugging an Azure Web App running in the cloud, it can be ensured that all the deployment, configurations, operating system, etc are the same as the environment that’s exhibiting the issue. This includes the Application Settings, Connection Strings, SQL Database, Azure Blob Storage, DocumentDB, Azure Service Bus, or any other service the Web App is configured to use in a particular environment. Even if the environment being debugged is a copy of Production, or a Staging deployment slot, at least it’s likely 99% closer in configuration and setup than the developers localhost workstation.
Once the bug is squashed and the issue is resolved by using Azure Web App Remote Debugging, the developer can then make the fix to the development branch of the codebase, add specific unit tests, or any other activity necessary to ensure the bug never reappears.
Happy remote debugging, and fix those hard to troubleshoot bugs!