views:

44

answers:

3

I have a URL. Is it possible to somehow get the controller- and action-name and the routevalues? (which would normally be generated by the .NET MVC framework based on the definition in global.asax)

A: 

No, this is not possible.

Paul Creasey
Thanks for you highly motivated answer
Ropstah
Well i assumed by "I have a URL" you weren't referring to your own site, in which case it is impossible. But i suppose that Alexander Taran's answer does make sense if thats what your after, and it's very useful for debugging complex routes.
Paul Creasey
+3  A: 

It is possible, check Haacked routing debugger.

Alexander Taran
I suppose I had better ask - why do you want to know this? making decision based upon the names of controllers/actions/route-values is going to make you code less loosely coupled.
belugabob
+2  A: 

Where and when do you want to get the values?

From within your code you can call:

HttpContextBase context = new HttpContextWrapper(HttpContext.Current);
RouteData rd = RouteTable.Routes.GetRouteData(context);

if (rd != null) {
    string controllerName = rd.GetRequiredString("controller");
    string actionName = rd.GetRequiredString("action");
}

Please note that this only works from within your application's code. There is definitely no way to get this information about other sites and applications.

Eilon