Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get access to the current System.Web.Routing.RequestContext from within a custom helper method in ASP.NET MVC?

Tags:

I'm writing a helper method for ASP.NET MVC and I need to call Url.Content to get an appropriate URL for the context. However, in order to create a new UrlHelper() I need to get the current RequestContext (System.Web.Routing.RequestContext to be precise) and I'm not sure how to grab it. Anyone know?

like image 451
JC Grubbs Avatar asked Dec 08 '08 22:12

JC Grubbs


1 Answers

If the current IHttpHandler is MvcHandler, you can use

((MvcHandler)HttpContext.Current.Handler).RequestContext 
like image 149
felixg Avatar answered Oct 04 '22 03:10

felixg