asp.net mvc 错误页面

参考文章
https://shiyousan.com/post/635838881238204198

https://www.cnblogs.com/TomXu/archive/2011/12/15/2285432.html

HandleErrorAttribute使用

web.config配置(不是views下面的)

  <customErrors mode="On"> </customErrors>
只要项目中的控制器和操作方法有抛出异常,默认就会被HandleError特性捕获,从而跳转到默认的错误详细页面~/Views/Shared/Error.cshtml。

<hr />

HandleErrorAttribute不处理“4xx”错误,所以在配置中自定义错误

  <customErrors mode="On" defaultRedirect="~/Error/HttpError">
      <error statusCode="404" redirect="~/Error/NoFound"/>
    </customErrors>

备注:redirect=“~/controller/action/”

        当发生404错误时,页面跳转NoFound.cshtml;

        defaultredirect是设置为所有自定义错误页面转向的错误页面地址;例如,若发生403错误,因为没有配置

   <error statusCode="404" redirect="~/" />
        所以当发生403错误默认跳转到 defaultRedirect="~/Error/HttpError"  HttpError.cshtml



猜你喜欢

转载自blog.csdn.net/jianghuai_j/article/details/79915183
今日推荐