How to add a default error page using httpErrors

后端 未结 2 1091
眼角桃花
眼角桃花 2020-12-20 17:31

i have successfully added a custom 404 page. what I want to do is to create another custom error page that is displayed when there is any error other than 404. e.g. 500, 403

相关标签:
2条回答
  • 2020-12-20 18:17

    Oh, my. I cannot believe I could not find a proper answer for this simple question! Nevertheless, after 2 hours of reading the docs and debugging, I found it.

    <httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" defaultPath="/App/Error"> <!-- Do not include ~, this was my issue all long -->
      <clear/> <!-- so that IIS provided error pages are skipped -->
      <!-- add those which you like to provide a view of yours -->
      <error path="/App/Http404" responseMode="ExecuteURL" statusCode="404"/>
      <error path="/App/Http503" responseMode="ExecuteURL" statusCode="503"/>
    </httpErrors>
    

    Beaware that <httpErrors> configures IIS, while <customErrors> configures ASP.NET and some older versions of IIS (<=6?).

    0 讨论(0)
  • 2020-12-20 18:24

    You can use customErrors in webconfig :

    <customErrors mode="On" defaultRedirect="~/DefaultError.aspx?msg=SomeMessage">
      <error statusCode="404" redirect="~/PageNotFound.html"/>
      <error statusCode="403" redirect="~/AccessDenied.html"/>
    </customErrors>
    
    0 讨论(0)
提交回复
热议问题