views:

31

answers:

2

I have several routes defined in my Global.asax; now, when I'm on a page I need to figure out what is the route name of the current route, because route name drives my site menu. I can't find a way to get current route name.

Any help would be highly appreciated! Andrey

+1  A: 

I have been facing the same dilemma, and I came to the conclusion that unfortunately, there doesn't seem to be a way to find out which route (by its name) the ASP.NET has picked for usage.

It seems you can only figure that out by the names of the parameters that might exist in your route - those will show up in the RouteData.Values dictionary.

If someone knows a way to somehow get at the actual name of the route picked by ASP.NET for a given URL, I'd be interested to know how to do that myself, too!

marc_s
Yeah, that stinks! They have a private map that holds names and routes, but there is no way of exposing it :(
Andrey
+2  A: 

Unfortunately, it's not possible to get the route name of the route because the name is not a property of the Route. When adding routes to the RouteTable, the name is used as an internal index for the route and it's never exposed.

There's one way to do this.

When you register a route, set a DataToken on the route with the route name and use that to filter routes.

The easiest way to do #1 is to probably write your own extension methods for mapping routes.

Haacked