Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?
NOTE: I don't want to set this up in my IIS settings.
Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?
NOTE: I don't want to set this up in my IIS settings.
If the route cannot be resolved, then MVC framework will through 404 error.. Best approach is to use Exception Filters ... Create a custom exceptionfilter and make like this..
An alternative to creating a catch-all route is to add an
Application_EndRequest
method to yourMvcApplication
per Marco's Better-Than-Unicorns MVC 404 Answer.Inside
RouterConfig.cs
add the follwing piece of code:Add this lines under your project root web.config File.
This might be a problem when you use
When you want to catch that, I don't know any other way then editing your web config.
Found the answer myself.
Richard Dingwall has an excellent post going through various strategies. I particularly like the FilterAttribute solution. I'm not a fan of throwing exceptions around willy nilly, so i'll see if i can improve on that :)
For the global.asax, just add this code as your last route to register: