Show ASP.NET 5 error page in Azure web app
Asked Answered
N

7

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.

Nourishment answered 13/8, 2015 at 15:10 Comment(1)
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.Metaphase
N
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.

Nourishment answered 14/8, 2015 at 6:21 Comment(4)
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.Squadron
I'm STILL fighting with these problems. Very frustrating and not intuitive.Nourishment
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.Squadron
That worked for me too. It's been 20 years and the fix for most ms products is still either rebooting or reinstalling.Bohlen
E
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
}
Eupatorium answered 25/11, 2015 at 12:42 Comment(5)
Thanks for updating an old question.Nourishment
Thanks, currently running RC1 and this was helpful!Nygaard
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!!Longish
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.Thurifer
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.Prevost
N
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.

Nourishment answered 14/8, 2015 at 6:21 Comment(4)
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.Squadron
I'm STILL fighting with these problems. Very frustrating and not intuitive.Nourishment
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.Squadron
That worked for me too. It's been 20 years and the fix for most ms products is still either rebooting or reinstalling.Bohlen
S
3

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

<system.web>
  <customErrors mode="Off" />
</system.web>
Spurt answered 13/8, 2015 at 15:15 Comment(6)
This is ASP.NET 5. There is no web.config.Nourishment
Oh sorry I haven't used ASP.NET 5 yet I presumed it would still be there.Spurt
You need to add one yourself. See docs.asp.net/en/latest/fundamentals/diagnostics.htmlExtern
I have the same problem as @davenewza. I have tried very bit of advice (including this one) and I still get nothing.Squadron
@jessegavin: Check out my answer.Nourishment
adding the web.config setting plus the App setting ASPNET_ENV : Development in the Azure portal worked for me. Thanks contributorsEvertor
L
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.

Lees answered 14/8, 2015 at 12:26 Comment(4)
I'll need to try the Diagnostics feature. First I have to upgrade the app to Standard.Squadron
In your experience what is the reason the 'runtime is borked' - whatever that means ;-) ? And what was the solution? Thanks.Metaphase
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)Lees
Also, one good way to diagnose startup errors is to build the same package locally and run it via the command line.Lees
S
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();
      ...
     }
Sepia answered 30/11, 2016 at 8:9 Comment(0)
J
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.

Jewell answered 21/9, 2015 at 6:13 Comment(0)
M
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>
Murrey answered 2/12, 2015 at 23:36 Comment(1)
Why are you still on beta5?Nourishment

© 2022 - 2024 — McMap. All rights reserved.