Azure App Service - Edit Web.Config Remotely Using Visual Studio

Please refer to my following articles to understand how to connect an Application located in your local environment to an Azure app Service.

Most of the .NET developers are familiar with debugging on their local Visual Studio IDE, which helps them to troubleshoot the errors, which occur in their local environment with a proper message in the Browser. For this demo purpose, let’s create a simple page named WebForm1.aspx and create a simple custom exception in the Page_Load event, as shown below:
Let’s run the Application by clicking Ctrl + F5 to view the page in the Browser.


For a developer, it’s easy to understand the exception and provide a fix in the local environment. Let’s publish this page to Azure and see what happens, when you access the page in Azure.


As per the screenshot, shown above, it’s not clear about what exactly the problem is because by default; the errors are disabled on Production environment.

In order to view the detailed error message, we need to set the customError mode to “Off” in the Web.Config.

In order to do this, we need to download the Web.Config file, using a FTP tool something like FileZilla, make changes to the Web.Config file and then upload the file to the Production environment, which might be complex for some of us.

Visual Studio comes with a simple way for making the changes to the Web.Config, located in the remote location on Azure. Let’s see, how to make the changes.

In the Server Explorer, expand the resource group, where your app Service is located. In my case, “Error Logging” is the name of my Resource Group and “Diagnostic Examples” is the name of my app Service.

my App Service

Expand the “Files” folder, locate your Web.Config file, double click the same to download the same and open it in your Visual Studio IDE , as shown below:


Notice, the [Remote] in the screenshot, shown above. It means, you are directly updating the remote Web.Config file, right from your Visual Studio.

Let’s add the following Custom Errors attribute to the Web.Config file, which displays the error messages.

  1. <configuration>  
  2.     <system.web>  
  3.         <customErrors mode="Off" /> </system.web>  
  4. </configuration>  

Once you save the changes, the following alert will be shown:

Click “Save Changes” to save the changes in Azure app Service.

Save Changes
After few seconds, the changes will be saved to Azure. Now, refresh the page of your Azure app Service Web app to view the actual error message, as shown below:


Note: This setting shouldn’t be done on the Production Sites. You should use some third party (or your own solutions) for Error Logging (like ELMAH etc.), which provides a single view for all your exceptions and errors. Configuring the custom errors to OFF will disable the redirections to custom error pages.

That’s it. We learned how to edit the Web.Config file from Visual Studio on a remote desktop. Hope, you enjoyed the article. Your feedback is highly appreciated.