ASP.NET 5自定义错误页面不呈现在Azure网站 [英] ASP.NET 5 custom error page does not render on Azure Website

查看:242
本文介绍了ASP.NET 5自定义错误页面不呈现在Azure网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 5个网站,我想添加自定义错误页面。我已经习惯了在web.config中添加条目(从ASP.NET 4天),但我想用在ASP.NET 5.新的方法所以我的,我Startup.cs类以下内容:

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");
}

当我运行本地使用kestral正确显示我的错误页面。然而,当我部署到Azure中,我得到了非常普通的白色错误页面,当我尝试测试404错误:

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."

我试图实施我的web.config这个答案并没有解决我的问题:

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

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

这是我的web.config的相关部分:

This is the relevant part of my web.config:

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

我也保证ASPNET_ENV =生产中的Azure网站的配置/应用程序设置部分。

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.

推荐答案

IIS是一个棘手的野兽,我们在ASP.NET 5.通过本仍然工作当你运行在IIS上,我们通过中间件管道运行,然后回调到IIS本机模块,如果没有处理的请求。当你得到一个404,是由任何中间件联合国处理,它会重新进入IIS管道和触发特定的IIS错误页面。所述UseStatus codePagesWithReExecute中间件仍然运行,但那时,IIS已经发送的头部和主体向客户端(在这种情况下的浏览器)。

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).

这篇关于ASP.NET 5自定义错误页面不呈现在Azure网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆