Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Access RouteData for the current Route from a library class in asp.net mvc October 7, 2009

Filed under: Asp.Net, C#, MVC — Rupert Bates @ 1:20 pm

Sometimes it’s useful to be able to access the current RouteData from outside a controller, for instance in a library class. In webforms you could always do


HttpContext.Current

but in Asp.Net MVC it’s a bit less obvious how you get access to this data.

I’ve found the following code works:


RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));

Whether there is an easier way or not I don’t know, but this will do me for now…


 

One Response to “Access RouteData for the current Route from a library class in asp.net mvc”

  1. [...] to VoteAccess RouteData for the current Route from a library class in asp.net mvc (10/7/2009)Wednesday, October 07, 2009 from eliasbland.wordpress.comCurrent but in Asp. Net MVC it’s a bit [...]


Leave a Reply