ASP.NET 5 custom error page does not render on Azure Website

折月煮酒 提交于 2019-12-20 00:00:55

问题


I have a ASP.NET 5 site that I want to add custom error pages to. I'm used to adding entries in the web.config (from ASP.NET 4 days) but I want to use the new approach in ASP.NET 5. So I have the following in my Startup.cs class:

if (env.IsEnvironment("Development"))
{
    app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
    app.UseStatusCodePagesWithReExecute("/Home/Error");
    app.UseErrorHandler("/Home/Error");
}

When I run locally using kestral my error page is displayed properly. However, when I deploy to Azure I get the very generic white error page when I try to test 404 errors:

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

I tried implementing this answer in my web.config and it does not resolve my issue:

https://stackoverflow.com/a/29539669/8320

This is the relevant part of my web.config:

<system.web>
    <customErrors mode="Off" />
</system.web>

I have also ensured that ASPNET_ENV="Production" in the Configure / App Settings section of the Azure Website.

Any ideas? If I can provide more info let me know.


回答1:


IIS is a tricky beast and we're still working through this in ASP.NET 5. When you run on IIS, we run through the middleware pipeline and then call back into IIS native modules if nothing handled the request. When you get a 404 that was un-handled by any middleware, it will re-enter the IIS pipeline and trigger IIS specific error pages. The UseStatusCodePagesWithReExecute middleware still runs, but by then, IIS has already sent the headers and body to the client (browser in this case).



来源:https://stackoverflow.com/questions/30902135/asp-net-5-custom-error-page-does-not-render-on-azure-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!