4

I have web.config settings like this

<customErrors mode="On" > <error statusCode="404" redirect="~/404" /> <error statusCode="403" redirect="~/500" /> <error statusCode="500" redirect="~/500" /> </customErrors> 

and for httperrors

 <httpErrors errorMode="Custom" > <error statusCode="400" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_request.html" /> <remove statusCode="401" subStatusCode="-1" /> <error statusCode="401" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unauthorized.html" /> <remove statusCode="403" subStatusCode="-1" /> <error statusCode="403" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\forbidden.html" /> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" /><remove statusCode="405" subStatusCode="-1" /> <error statusCode="405" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\method_not_allowed.html" /><remove statusCode="406" subStatusCode="-1" /> <error statusCode="406" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_acceptable.html" /> <error statusCode="407" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\proxy_authentication_required.html" /><remove statusCode="412" subStatusCode="-1" /> <error statusCode="412" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\precondition_failed.html" /> <error statusCode="414" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\request-uri_too_long.html" /><error statusCode="415" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unsupported_media_type.html" /> <remove statusCode="500" subStatusCode="-1" /><error statusCode="500" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\internal_server_error.html" /> <remove statusCode="501" subStatusCode="-1" /><error statusCode="501" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_implemented.html" /> <remove statusCode="502" subStatusCode="-1" /><error statusCode="502" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_gateway.html" /> <error statusCode="503" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\maintenance.html" /> </httpErrors> 

On 404 Error. Skipping 404 page and goes to .aspxerrorpath= page.aspx and writing The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

I want to show my customized 404, 500 error page. What is the wrong

2
  • Remove absolute paths. Add custom error pages to you default root directory of your project and then add relative paths. This should work. Commented Nov 24, 2017 at 11:57
  • I'm pretty sure that if you create a 404.html file and put it in your root folder, it should pick it up. Commented Dec 1, 2017 at 3:35

1 Answer 1

1
+25

In short, in production it is possible to completely get rid of the "system.web -> customErrors" section, which is almost kept for the compatibility purposes (check the What is the difference between customErrors and httpErrors? thread to learn more), and where you also specify redirects. Then, specify the necessary redirects and custom error pages within the "system.webServer -> httpErrors" section only. Make sure that these HTML files exist on the web server and are available via the relative paths (or these pages exist inside one of a parent web app on the same web server, so that these "errors" settings are inherited).

Solution Explorer:

~/YourWebApp

  • ...

  • not_found.html

  • Web.config

Web.config (for the 404 status code error):

<!--Dev: For Visual Studio Mode--> <system.web> <customErrors mode="On"> <error statusCode="404" redirect="~/not_found.html" /> </customErrors> </system.web> <!--Prod: For IIS Mode--> <system.webServer> <httpErrors errorMode="Custom"> <!--<error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" />--> <error statusCode="404" path="~/not_found.html" responseMode="Redirect" /> </httpErrors> </system.webServer> 
Sign up to request clarification or add additional context in comments.

1 Comment

For 404 status, it works. But 500 is going 404 page. Why ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.