Asp.net does not display custom 404 page with customization

in my web config I have:

<customErrors mode="On"> <error statusCode="404" redirect="~/error/404.aspx" /> </customErrors> 

http: // localhost / meh <- standard 404 is shown

http: //localhost/meh.aspx <- user number 404 is displayed

http: //localhost/error/404.aspx <- user error page that I want to show for all 404 errors

How do I configure my web.config to send all 404 of my custom error?

thanks

+4
source share
2 answers

You must configure this in IIS. By default, only certain files will be routed through the ASP.NET infrastructure ... otherwise IIS will handle this. enter image description here

+2
source

Use the Application_Error event handler in the global.asax file to redirect the user to ~ / error / meh.aspx

in global.asax

  protected void Application_Error(object sender, EventArgs e) { Response.Redirect("~/error/404.aspx"); } 

In your web.config also add

  <customErrors mode="On" defaultRedirect="/error/404.aspx" /> 
-1
source

Source: https://habr.com/ru/post/1342179/


All Articles