I played with ASP.Net MVC for a while. I found that the hardest part is the routing table.
I found that most examples leave the default route in place. I found that this leads to a lot of errors when the default route redirects an action to the HomeController that does not exist. Leading to strange error messages where you expect to see a simple 404.
In the end, I decided to set up routing, where I explicitly define all the controller / action combinations that I want to allow, with a full interception at the end to redirect to page 404, which shows a reasonable error message.
Am I missing something? Or is this a really good way to do something?
Looking at the answers that I have, I think I better clarify the question.
I am trying to check the routing version of the website that I am creating. I noticed that when I go to the default route {controller} / {action} / {id}, all types of URLs where I would like to display a 404 error do get routing in the HomeController with an invalid action and lead to some ugly error instead.
I'm a bit confused because most code examples just go to the default route. Is there a reason it is, or is it normal to remove it?
The circuit I use looks a bit like this
routes.MapRoute( "About", "About", new {controller = "Page", action = "About"} ); routes.MapRoute( "SignIn", "SignIn", new {controller = "Page", action = "SignIn"} ); routes.MapRoute( "SignOut", "SignOut", new {controller = "Page", action = "SignOut"} ); routes.MapRoute( "Authenticate", "Authenticate", new { controller = "Authentication", action = "Authenticate" }); routes.MapRoute("CatchAll", "{*url}", new { controller = "Error", action = "Http404" });
I have a route specified for each action in the system. And enough to display 404 at the end. Is this a good way to do this, or is there an easier way to make the routing scheme flawless?