权威指南处理在IIS6,IIS7,ASP.NET MVC3 500错误自定义页面 [英] Definitive Guide to Handling 500 Errors in IIS6, IIS7, ASP.NET MVC3 with Custom Page

查看:128
本文介绍了权威指南处理在IIS6,IIS7,ASP.NET MVC3 500错误自定义页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个500错误处理页面添加到我的ASP.NET MVC3项目。

I'm trying to add a 500 error handling page to my ASP.NET MVC3 project.

我想,无论本地或远程访问显示我的自定义错误页。
我的网站是在IIS6,IIS7和放大器运行; IIS7.5防爆preSS

I want my custom error page displayed regardless of local or remote access. My website is running on IIS6,IIS7 & IIS7.5 Express

我希望它显示时:


  • 一个例外是抛出的Application_BeginRequest

  • 一个例外是抛出的Application_Error

  • 一个例外是在网站项目静态构造函数抛出

  • 一个例外是在一个控制器抛出

  • 一个例外是在一个视图抛出

  • 的任何地方抛出的异常pretty多。

我一直没能在这做的,其实我一直没能得到任何自定义错误页,以显示在所有。

I haven't been able to do in this, in fact I haven't been able to get any custom error pages to display at all.

我的错误页面住在〜/查看/共享/ Error.aspx

在Global.asax.cs中我的Application_Error方法只记录被抛出的异常。

My Application_Error method in Global.asax.cs just logs the thrown exception.

我的web.config中有这样:

My web.config has this:

<customErrors mode="On" defaultRedirect="~/Views/Shared/Error.aspx" redirectMode="ResponseRewrite">
</customErrors>
...
<system.webServer>
  <httpErrors errorMode="Custom" />
  ...
</system.webServer>

我在想什么?什么我需要做的来处理这些情况?

What am I missing? What do I need to do to handle these scenarios?

推荐答案

有关IIS 7 +,你只缺一个定义部分的 httpErrors与自定义处理程序来处理:

For IIS 7+, you're only missing the part that defines which httpErrors to handle with custom handlers:

<configuration>
   <system.webServer>
      <httpErrors errorMode="Custom">
         <remove statusCode="500" />
         <error statusCode="500" path="~/Views/Shared/Error.aspx" />
       </httpErrors>
   </system.webServer>
</configuration>

(即&LT;删除/方式&gt; 标签是可选的,取决于你的web.config层次)

(The <remove /> tag is optional, depending on your web.config hierarchy.)

有关IIS 6及以下,您可通过IIS管理器通过转到相应的属性页面设置此,自定义错误选项卡,然后编辑相应的HTTPError这样行消息类型:网址和URL 〜/查看/共享/ Error.aspx。

For IIS 6 and below, You have to set this via the IIS Manager by going to the appropriate Properties page, Custom Errors tab, then edit the appropriate HTTPError line to "Message type:" "URL" and "URL:" "~/Views/Shared/Error.aspx".

这篇关于权威指南处理在IIS6,IIS7,ASP.NET MVC3 500错误自定义页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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