Azure Web Sites: Troubleshooting “Server Error in '/' Application” errors

 

A “Server Error in ‘/’ Application” error when browsing your Microsoft Azure Web Site can be a bit tricky to troubleshoot if you don’t know where to look for information.

Here is an example of one of these errors. As you can see, although it does not tell you the root cause of the error, it does tell you how to troubleshoot the error in the Details section. In this post we will cover how to enable CustomErrors as well as some other logging that may help diagnose these issues.
 

Server Error in '/' Application.


Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

 <!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

 <!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

 

Troubleshooting

 
First we will cover the built-in logging in Azure Web Sites and what this shows for this error.  If you are not familiar with how to connect to your site using FTP see

How to FTP into a WAWS Site

Web Server Logging:

As you can see here, the web server logging shows an HTTP status (sc-status) of 500 with a sub-status (sc-substatus) of 0 and a Win32 status (sc-win32–status) of 0. This information doesn’t get us any closer to understanding the root cause of the error, but I do recommend checking this as in some cases these codes provide additional information. For example the status code might be something like 500 19 where the 19 is a significant piece of information see HTTP 500.19 Errors

For this case we will focus on the  500 0 0 as shown in the follow IIS log entry ( Note we have removed some of the fields you might normally see.)

 
date time s-sitename cs-method cs-uri-stem sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken

2014-04-18 19:45:06 RMARRAZUREMGMTAPI GET /servererror.aspx 500 0 0 3847 944

 
More information on HTTP status codes can be found here:  HTTP Status Codes

Detailed Errors

The Detailed Errors logs are located in the Logfiles/DetailedErrors folder. A log file named ErrorPagexxxxxx.htm is created for each HTTP Status code of 400 or greater.

From the name of the log, logically you might think to look here next , but from an exception perspective, this is not too helpful in this case.

  image

 

EventLog.XML

The eventlog.xml file is located in the root of the  LogFiles folder of your site. It may contain additional information about why an error occurred. In the example below, we see that there was an unhandled exception of type "NullReferenceException" that occurred in  ServerError.aspx.cs in the Page Load  method.

ServerErrorBlog1

In many cases, this information may be all you need to fix the problem, but there might be cases where you need more details.

This is where the customErrors settings may be helpful.

CustomErrors

The customErrors section  along with the compilation debug settings can help when you need more details about an error and the code where the error originated.

WARNING: This setting will expose your code to external users. Remove these settings after troubleshooting.

To use the customErrors section, add the following to the <system.web> section of the web.config for your site:

 <customErrors mode="Off"/>  
<compilation debug="true">

Reproduce the error and now you should see the exception details and the line of code where it originated.

Server Error in '/' Application.


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

 Line 10:     protected void Page_Load(object sender, EventArgs e)
Line 11:     {
Line 12:         throw new System.NullReferenceException();
Line 13:     }
Line 14: }

Source File: d:\home\site\wwwroot\ServerError.aspx.cs    Line: 12

Stack Trace:

 [NullReferenceException: Object reference not set to an instance of an object.]
   ServerError.Page_Load(Object sender, EventArgs e) in d:\home\site\wwwroot\ServerError.aspx.cs:12
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Obviously this is a simple example and we know the cause of the exception, but in the real world your next step may require debugging. The following blog post provides information on how to remotely debug your application in Azure Web Sites.

https://blogs.msdn.com/b/webdev/archive/2013/11/05/remote-debugging-a-window-azure-web-site-with-visual-studio-2013.aspx

For an example of how to get the root of an exception without using CustomErrors see Using ELMAH in Windows Azure Web Sites .

References:

Custom Errors Element

https://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.85).aspx

Troubleshooting Azure Web Sites in Visual Studio

https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-visual-studio/