I understand how to set up my own routes, but how does one handle routes that fall through the cracks of the routing table? I mean, I guess the default {controller}/{action}/{id} route could be a generic catchall, but I’m not sure if that’s the way to go. I like letting my users know they’ve requested data/a ‘page’ that doesn’t exist.
Is this where the [HandleError] filter comes in? How does that work, exactly?
If your route is not found, you want to handle it as a normal HTTP 404 error.
If you only add the
[HandleError]attribute to your class or action, MVC will look for anErrorview in your views folder.You could also add an
ErrorControlleror even a static page and add this to yourWeb.config:Or you could handle the HTTP 404 in your
Global.asax.csand route to anErrorControllerprogrammatically. That’s how I generally do it: