为什么404自定义错误起作用而500自定义错误不起作用?

问题描述 投票:0回答:1

我已经在我的web.config中实现了CustomErrors。 404错误按预期工作,500错误仅显示一个空的默认布局页面,在RenderBody区域中显示标准生成的.NET HTML输出。

web.config中的代码是:

<customErrors mode="On">
  <error statusCode="404" redirect="~/404.html"/>
  <error statusCode="500" redirect="~/500.html"/>
</customErrors> 

404可以在这里看到:http://www.airportcars-gatwick.com/i-do-not-exist

这里可以看到500:https://taxis.gatwickairport.com/Book?Q=9fa5-514e-4c3a-972f8baee58fa2b9

(两个文件都在服务器上的相同根位置)

这是HTML页面插入到RenderBody中的布局页面

</div>
 </header>
 <!-- //Header -->

 <!DOCTYPE html>
 <html>
  <head>
   <meta name="viewport" content="width=device-width" />
   <title>Error</title>
  </head>
  <body>
   <hgroup>
    <h1>Error.</h1>
    <h2>An error occurred while processing your request.</h2>
   </hgroup>
  </body>
 </html>

<!-- Footer -->
<footer class="footer teal" role="contentinfo">
    <div class="wrap">
 ..etc...

不确定我缺少什么?

asp.net-mvc web-config
1个回答
0
投票
GlobalFilters是一种将属性与ASP.NET MVC应用程序中的每个Action方法相关联的方法。我想我的项目已经自动为我解决了。

在我的app_start文件夹中的FilterConfig.cs文件中:

public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } }

因此,通过注释掉Global.asax.cs文件中的RegisterGlobalFilters行,此问题已解决。

protected void Application_Start()
    {
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); // Comment out

希望这对其他人遇到相同的行为有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.