I am using Routing in my website. What I want to do, is to detect when user enters invalid url and catch error in Application_Error (in Global.asax) and then redirect user to Home page.
For testing I use just one route:
routes.MapPageRoute("myroute","Home/{id}/{age}", "~/Home.aspx",false);
So if I go to http://testsite/Home/10/25 all works fine.
If I go to http://testsite/Home/10/25/3443/33/22 server returns "404 Not Found" error. The problem is that Application_Error is not even firing here.
BUT if I go to If I go to http://testsite/Home/10/25/3443/33/22.aspx then Application_Error is firing
Does anyone know why? How can I catch ALL the errors and redirect user to Home page?
P.S. My web.config is:
<customErrors mode="Off" defaultRedirect="Home.aspx">
<error statusCode="404" redirect="Home.aspx" />
</customErrors>