28

I am getting a 500 Internal Server Error when deploying our ASP.NET 5 web application to an Azure Web App.

enter image description here

How do I get the details and stacktrace for this exception?

I have done the following but with no luck:

  • Using the diagnostics error page on startup:

    app.UseErrorPage();

  • Setting ASPNET_ENV in Azure portal:

Azure Web App app settings

Using DNX beta 6.

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 2
    I just spent half a day trying to debug the 500 error on Azure with absolutely no luck. Wasn't even getting as far as startup - so no use adding exception handling! I created new MVC project and deployed to the same azure site with the same publishing settings, and that worked fine. Re published the failing site. Same 500 error. In the end I created new website on azure and deployed to that. Worked first time. So what was the problem? This really worries me for production deployments. No errors, no way to debug, no problem with the code or deployment method/configuration. – Mark Chidlow Mar 12 '16 at 00:28

7 Answers7

30

In case this helps someone, I've found out that if you're using ASP.NET RC1 and you're using Azure WebApps and add an App setting called Hosting:Environment with a value of development a stack trace for server 500 errors will display.

enter image description here

For this to work the Configure method in the Startup.cs needs to use the Developer Exception page when you're using the Development environment. Eg:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }

    // etc
}
neodymium
  • 3,686
  • 6
  • 23
  • 31
  • Thanks for updating an old question. – Dave New Nov 25 '15 at 12:58
  • Thanks, currently running RC1 and this was helpful! – corkington Dec 13 '15 at 22:32
  • 1
    In Core 1.0.0 adding the "Hosting:Environment" App setting in Azure caused the whole error to display. Nothing else worked for me. Thanks!! – Kizmar Jul 18 '16 at 18:45
  • Huge help! Thank you! – neverseenjack Sep 26 '16 at 16:53
  • It works for me, thanks! I am migrating .Net core 1.0 app to 2.0. It throws this 500 error after trying to navigate to a user list. I've tried remote debug, no help. logs/stdout folder setting via web.config, no help. this solution is simple and helpful. – Joseph Wu Nov 15 '17 at 02:35
  • Setting "Hosting:Environment" with a value of "development" was all I needed to get decent errors out of my app today, didn't need the code change. Thank you so much for this, it was driving me nuts being unable to see the problem. – Mike Feb 16 '18 at 10:38
4

According to this post (thanks Muhammad), I should be able to get the runtime error on Azure by editing the server's web.config (quite correct, Celt).

Unfortunately this did not work - no detailed exception.

I did some digging around and found these "DetailedError" logs:

DetailedErrors

This is what they contained:

HTTP Error 500.0 - Internal Server Error

It appears that something may have been going wrong when trying to resolve favicon.ico at D:\home\site\wwwroot\favicon.ico.

There indeed was no favicon at that location. I rectified this, but still the same problem. In fact, I have never had a favicon, and this used to work.

In the end, I deleted the entire Web App in Azure Portal and republished... TADA, it works again.

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 1
    Ugh. Maybe I should just delete and start over too. I had already looked through all the detailed error logs, enabled trace debugging, etc. Nothing gives me any answers. – jessegavin Aug 14 '15 at 16:22
  • I'm STILL fighting with these problems. Very frustrating and not intuitive. – Dave New Sep 09 '15 at 15:38
  • I was able to determine the cause of the problem by commenting out all the code in startup.cs, then un commenting bits and pieces until I found the offending code. It ended up being a database connection string issue for me. This was a _terrible_ problem. – jessegavin Sep 09 '15 at 17:03
  • That worked for me too. It's been 20 years and the fix for most ms products is still either rebooting or reinstalling. – micah Feb 12 '17 at 21:48
3

Try setting your customErrors mode to off in your Web.config file like this:

<system.web>
  <customErrors mode="Off" />
</system.web>
Celt
  • 2,469
  • 2
  • 26
  • 43
3

When you get an HTTP 500 from an Azure Web Application that's running ASP.NET 5 and you can't get a detailed error output, in my experience it's for one of two reasons:

  • Your Startup.cs is causing the problem
  • The runtime cannot be loaded

For dealing with the first type of issue, you're best off writing an error handler that will log startup errors somewhere (we use Raygun.io for that, your needs and preferences should determine your solution).

For the second kind, the best I've come up with is through the Diagnostics feature of Web Sites -- you can access the Windows Server Event Logs, which will tell you if your runtime is borked.

Rytmis
  • 31,467
  • 8
  • 60
  • 69
  • I'll need to try the Diagnostics feature. First I have to upgrade the app to Standard. – jessegavin Aug 14 '15 at 16:23
  • In your experience what is the reason the 'runtime is borked' - whatever that means ;-) ? And what was the solution? Thanks. – Mark Chidlow Mar 12 '16 at 00:35
  • Well, either the runtime is not packaged with the app or it's the wrong version (you can easily specify the wrong runtime for dnu publish) – Rytmis Mar 12 '16 at 10:18
  • 1
    Also, one good way to diagnose startup errors is to build the same package locally and run it via the command line. – Rytmis Mar 12 '16 at 10:19
2

Your startup.cs has some runtime code that isn't playing nice with Azure. Force the developer friendly exception page to render by moving app.UseDeveloperExceptionPage(); to the beginning of the Configure(...). Publish updated code to Azure, reload home page and exception will now be helpful.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
     {
          app.UseDeveloperExceptionPage();
      ...
     }
Christopher J.
  • 1,154
  • 1
  • 12
  • 21
evermeire
  • 479
  • 3
  • 7
1

I had exactly the same problems - always getting 500 and never seen a tiniest log or information what was wrong. Even after commenting out everything in Startup.cs and simply accessing static files I was getting 500 (though surprisingly sometimes the static file was served correctly, it changed from publish to publish of the same app).

I suppose that some file(s) got corrupted in my deployment and azure wasn't detecting it. Or maybe there were some files left on the server that caused conflicts during runtime - next time I think it would be also worth to change publish profile to not keep extra files on server (by default they are not deleted).

I ended up removing and re-creating the app, which solved the problem.

nazgul
  • 449
  • 1
  • 4
  • 10
0

If you're still on old versions of the DNX stack like myself (using beta5, which is what shipped with Visual Studio 2015), they had a setting that wasn't really documented well. I believe this has been changed since then, but here's what you had to place in your web.config:

  <appSettings>
    <add key="ASPNET_DETAILED_ERRORS" value="true" />
  </appSettings>