问题
I am getting a 500 Internal Server Error when deploying our ASP.NET 5 web application to an Azure Web App.
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:
Using DNX beta 6.
回答1:
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.
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
}
回答2:
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:
This is what they contained:
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.
回答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.
回答4:
Try setting your customErrors
mode to off in your Web.config file like this:
<system.web>
<customErrors mode="Off" />
</system.web>
回答5:
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();
...
}
回答6:
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.
回答7:
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>
来源:https://stackoverflow.com/questions/31992141/show-asp-net-5-error-page-in-azure-web-app