Trés DuBiel Trés DuBiel - 1 month ago 9
ASP.NET (C#) Question

Azure WebApp How to Get a Useful 500 error

I searched previous questions, first, but could not find anything that solved my issue. I have a Web App project that works fine locally, then fails with 500 after having been published. This is my first time using any of the Microsoft stack (C#, ASP.NET MVC, Azure), so bear with me.


  • Visual Studio 2015 Community

  • .NET 4.5 / ASP.NET 5 Web App project

  • StackExchange.Redis / Fleck / React.AspNET NuGet packages



I have added the following to
web.config
:

<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
...
<httpErrors errorMode="Detailed" />
<tracing>
<traceFailedRequests />
</tracing>
</system.webServer>


I also turned on
detailed error messages
under the web app's settings using the Server Explorer view in Visual Studio (right-click the app's name, click settings). I also attempted to remotely debug the web app, but received an "access is denied"("Remote debugging does not work in Express editions of Visual Studio" maybe?). So, I'll post the
web.config
from the Azure web app.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off"></customErrors>
</system.web>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpErrors errorMode="Detailed" />
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
<tracing>
<traceFailedRequests />
</tracing>
</system.webServer>
</configuration>


One or a combination of these changes mentioned above worked in providing a more useful error screen.

If someone can come along and post an answer as to which step(s) it may have been and why, etc. I'd be glad to accept it. I don't want to post an answer, as I honestly don't know which 'fixed' it.

Answer

You mention ASP.NET 5 Web App project so this means you have a Startup.cs file, right?

Check in your project.json file if you have (if not add it) the Microsoft.AspNet.Diagnostics package.

Then add on the public void Configure handler:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
        app.UseDeveloperExceptionPage();            
        //other app.Uses
}

This is intended for local dev because it will show the detailed full error, you might want to later add it in an if:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

Source: docs.asp.net

Comments