I need to use System.Web.Routing.RequestContext in a view model in order to call HtmlHelper.GenerateLink().
In MVC 1.0 it was possible to get the context statically by casting the current IHttpHandler:
var context = ((MvcHandler) HttpContext.Current.CurrentHandler).RequestContext;
Now the project has been upgraded to MVC 2.0 and this exception is thrown on the cast:
Unable to cast object of type ‘ServerExecuteHttpHandlerWrapper’ to type ‘System.Web.Mvc.MvcHandler’.
I’m not sure if it’s relevant but this is being run in .NET 4.0 on IIS6.
I don’t know what you wanna do with the
System.Web.Routing.RequestContext? check out: