Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a default error page using httpErrors

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 etc.

this is what I have right now in webconfig

<httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
    </httpErrors>
like image 699
btevfik Avatar asked Mar 27 '13 08:03

btevfik


People also ask

How do you display a custom error page with error code using httpErrors in asp net?

To display a custom error page with an appropriate error code, use the <httpErrors> section only, and do not use the <customErrors> section. Add the following <httpErrors> section under <system.

How do I change the default error page in web config?

Steps for Custom Error PageSet <customErrors> setting in Web. Config file of the application. Pass defaultRedirect and mode attributes in <customErrors>. If you want to set your application level exception should redirect to your custom error page, you can do this by going to global.


1 Answers

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?).

like image 138
Ghasan غسان Avatar answered Oct 17 '22 23:10

Ghasan غسان