7

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>
btevfik
  • 3,391
  • 3
  • 27
  • 39
  • checkout this link here maybe this gone help you http://www.iis.net/configreference/system.webserver/httperrors/error – Mingebag Mar 27 '13 at 08:53

2 Answers2

14

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

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
Ghasan غسان
  • 5,577
  • 4
  • 33
  • 44
  • 1
    Unfortunately, defaultPath attribute of httpErrors seems to be locked down in Azure. – Triynko Apr 11 '16 at 21:59
  • @Ghasan, what if we host application in azure or aws will this work ? – Light Jun 24 '19 at 04:30
  • @RakeshSadhula, I don't have experience with either. But judging from Triynko comment, it might not be working on Azure. – Ghasan غسان Jun 24 '19 at 06:37
  • 1
    What saved me was the comment that the tag Custom errors works for asp.net, most google results told me to get rid of it. – Osias Jota Dec 02 '20 at 15:07
  • 1
    @OsiasJota is for IIS6< is for IIS7+ (all the way until IIS10 so far). overrides . cannot deal with some errors such as 500 and 403. operates at IIS level, runs at application level. – Paul Zahra Mar 04 '21 at 14:06
-1

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>
mehdi
  • 1,755
  • 2
  • 15
  • 21
  • I tried customErrors but I couldn't get it to work. so switched to httpErrors. – btevfik Mar 27 '13 at 09:06
  • so you can see this [http://stackoverflow.com/a/7729351/2114572](http://stackoverflow.com/a/7729351/2114572) – mehdi Mar 27 '13 at 09:30