I'm attempting to implement custom error handling in my MVC 4 app. I'm not certain where in my web.config the <customErrors>
is supposed to go, and the general information I need to include in it.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
<customErrors>
goes inside <system.web>
:
<configuration>
<system.web>
<customErrors mode="RemoteOnly">
<error statusCode="500"
redirect="~/Error/InternalServer" />
<error statusCode="404"
redirect="~/Error/NotFound" />
</customErrors>
</system.web>
</configuration>
Modify values of the redirect
attributes according to your routes. You can also implement a catch-all redirect by adding a defaultRedirect
attribute to the customErrors
element. See this MSDN article for more information.