Asp.net-mvc – How to get access to the current System.Web.Routing.RequestContext from within a custom helper method in ASP.NET MVC

asp.netasp.net-mvc

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?

Best Solution

If the current IHttpHandler is MvcHandler, you can use

((MvcHandler)HttpContext.Current.Handler).RequestContext