I am attempting to route a URL that does not have a static action i.e. Users can create systems which can be represented by any string. I would like to have a URL like the following:
http://yousite.com/System/WIN1234/Configure
By default the routing mechanism thinks that WIN1234 is the action, whereas I would like to be able to catch WIN1234 and make a decision on which method to throw. As in:
public void RouteSystemRequest(string system, string action)
{
switch (action)
{
case "Configure":
ConfigureSystem(string system);
break;
}
}
开发者_开发百科
How can I accomplish this? Is this logical or am I thinking about this all wrong?
What you need to do is possible. You need to set up a default route that points to the System Action, and you need to accept the other values as parameters to the Action.
//General
routes.MapRoute(
"Default7", // Route name
"{action}/{param1}/{param2}", // URL with parameters
new { controller = "Home", action = "Index", param1 = "", param2 = "" } // Parameter defaults
);
In your code you will then get the values Win1234 and Configure as default.
You can then implement your switching logic and use RedirectToAction to move to the action you desire.
精彩评论