I am currently working on an asp.net mvc 4 application, and I have a need for the following type of URL:
URLs to redirect
The problem I am facing is that {username} is currently considered an action, so to solve this problem I have followed the following routes, but this will mean that every time I want to implement a new action, or controller that needs {username}, I will need to update my routes:
Showing only Foo routes
routes.MapRoute("FooSomeAction", "foo/someaction", new { controller = "Food", action = "SomeAction" });
routes.MapRoute("FooDelete", "foo/delete/{id}", new { controller = "Food", action = "Delete" });
routes.MapRoute(
"FooProfile",
"foo/{username}",
new { controller = "Foo", action = "Index", username = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
2 questions
1) Is there a way I can reach the above URLs without hard coding all the routes?
2) What is the best way to handle a situation where someone uses a username that is the same name as the controller name or name?
Dotnetshadow
source
share