I’d like to parse an incoming URL into it’s component parts for some pre-processing before passing it into the standard MVC routing logic. For example given your standard route
{controller}/{action}/{id}
and the URL
/user/show/10
Is there a way to have the Routing system return a dictionary containing controller, action and id keys with their corresponding values?
It’s pretty simple, the routing system is initialized at app start, and it calculates the route data based on the current context, so anytime the context itself is current, you’re all good.
In the Application_BeginRequest method of Global.asax, for example, you can get the current route data like so:
The routedata in turn has the RouteValueDictionary for the current request stored in its Values property and it has the data tokens stored in the DataTokens property.
Paul