Debugging HTTP 500 - Internal server error with Windows Azure SDK

Update November 2012 – See my new blog entry Debugging Azure HTTP 500 Errors. This blog no longer applies to Azure.

I was working on a lab using the Windows Azure SDK when I got 500 server error

clip_image002

Not a descriptive error message. The Windows Azure Tools for Microsoft Visual Studio (WATVS) creates a new application pool and web site on the fly when you run your Web application locally. The Azure tools do this to mimic how Azure runs applications in the cloud.  

The default setting on IIS for detailed errors is to only display for local addresses. (See https://learn.iis.net/page.aspx/267/how-to-use-http-detailed-errors-in-iis/ ).  To get a robust error message you need to use a local address.

You can get a local address by changing the site binding with IIS Manager.

  1. Select the web site in the connections pane, right click and select Edit Bindings.

    image

  2. In the Edit Site Bindings dialog, select the binding (the line in blue highlighting below), then select Edit.

    image
    clip_image002[6]

  3. Change the IP address from All Unassigned to * .

    image

    image

  4. OK, then Close.

  5. In IIS Manager, in the Actions pane, select Browse *.8x(http) .

    image

Now when you run the Azure application, you’re rewarded with rich error information. In my case, the root Web.config of the application had a duplicate section in the the  configSections element. The configSections is used  for registering all IIS and Windows Activation System (WAS) sections.

HTTP Error 500.19 - Internal Server Error

Config Error : There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined

image

I commented out the duplicate line and the application worked.

Alternate approach – Editing ApplicationHost.config

I was doing lots of labs, and each Azure application creates a dedicated web site and application pool (as mentioned previously, to more closely mimic Azure cloud deployment.) As you can see from the Sites pane in IIS manager, I have several Azure applications, and I would have to change the binding for each to get a local address.

image

Another approach you can take is to edit the ApplicationHost.config  file. You should only do this on your development machine, never on a production machine unless you know exactly what you’re doing.  ApplicationHost.config is the root file of the IIS 7 configuration system. It includes definitions of all sites, applications, virtual directories and application pools, as well as global defaults for the web server settings (similar to machine.config and the root web.config for .NET Framework settings). Any property set in ApplicationHost.config will apply to all sites, applications, and virtual directories in the machine. Because ApplicationHost.config contains the <section name="scriptResourceHandler" , I got a duplicate error in my root web.config file. To get rich errors information in all web sites, follow these instructions.

  1. Make a backup of ApplicationHost.config before making any changes to it.

  2. Edit  ApplicationHost.config with Visual Studio’s 32 bit editor by opening the file %windir%\sysnative\inetsrv\config\ApplicationHost.config
    32-bit Apps can access the native system directory by replacing %windir%\System32 with  %windir%\Sysnative
    Alternatively, using a 64 bit editor (such as notepad), open %windir%\System32\inetsrv\config\ApplicationHost.config

  3. Find the <httpErrors  element and add errorMode="Detailed". Replace

      <httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
    

    with

     <httpErrors errorMode="Detailed" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
    

Let me know if this helps out.

Rick.Anderson[at]Microsoft.com