How to avoid custom/Server error in web site?

I have web application located on server I want to avoid all custom and server error from my site.

For that I have used

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPage/TryAgainLater.aspx">   <error redirect="~/ErrorPage/PageNotFound.aspx" statusCode="404"/> </customErrors>

Using above code will able avoid some issue. ie.

Suppose "" Page available in my site then

Case 1. "It was working correct as per above rule".

Case 2.[email protected]##Careersss.aspx "Not working" Note : Here I add special character

Case 3: "Not working" Note : add character after ".aspx"

case 4:[email protected][email protected][email protected]! "Not works design breaking here". Note : Add '/' with special character.

please help me when user get case 2,3,4 then they automatically redirected to error page.

Thanks In advance.



If you don't want to change IIS settings, you can install your own handler for 404 errors in Global.asax. Just add this method to our Global.asax.cs code-behind file:

protected void Application_EndRequest(object sender, EventArgs e)
    HttpResponse response = HttpContext.Current.Response;
    if (response.StatusCode == 404 && response.SubStatusCode == 0)

If it does not fix the issue and you are still getting 404 error page, add this setting to your web.config file:

      <modules runAllManagedModulesForAllRequests="true"/>


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.