How can you access RouteData from the code-behind?

Deane picture Deane · Jun 10, 2009 · Viewed 26.5k times · Source

When using ASP.Net routing, how can you get the RouteData from the code-behind?

I know you can get it from the GetHttpHander method of the RouteHandler (you get handed the RequestContext), but can you get this from the code-behind?

Is there anything like...

RequestContext.Current.RouteData.Values["whatever"];

...that you can access globally, like you can do with HttpContext?

Or is it that RouteData is only meant to be accessed from inside the RouteHandler?

Answer

Hosam Aly picture Hosam Aly · May 12, 2011

You could also use the following:

//using System.Web;
HttpContext.Current.Request.RequestContext.RouteData