How to avoid user / server error on website?

I have an asp.net web application located on a server. I want to avoid all user and server errors from my site.

For this I used

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

Using the above code will avoid some problems. i.e.

Suppose the page "http://Exaple.com/Careers.aspx" is available on my site, and then

Case 1. http://Exaple.com/Careersss.aspx "It worked correctly in accordance with the rule above."

Case 2. http://Exaple.com/!@##Careersss.aspx "Not working" Note: here I add a special character

Case 3: http://Exaple.com/Careersss.aspxxxx "Doesn't work" Note: Add a character after ".aspx"

case 4: http://Exaple.com/Careersss.aspx/!@!@!@ ! "Design of works does not work here." Note. Add '/' with a special character.

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

Thanks in advance.

+8
javascript jquery html url-rewriting
source share
2 answers
+1
source share

If you do not want to change the IIS settings, you can set your own handler for 404 errors in Global.asax. Just add this method to our Global.asax.cs code file:

 protected void Application_EndRequest(object sender, EventArgs e) { HttpResponse response = HttpContext.Current.Response; if (response.StatusCode == 404 && response.SubStatusCode == 0) { response.Redirect("/test/TryAgainLater.aspx?error=NotFound"); response.End(); } } 

If the problem persists and you still get the 404 error page, add this parameter to the web.config file:

 <configuration> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration> 
+1
source share

All Articles