title: Accessing System.Web.Routing.RequestContext from static context in MVC 2.0
body: <p>I need to use <code>System.Web.Routing.RequestContext</code> in a view model in order to call <code>HtmlHelper.GenerateLink()</code>.</p>
  
  <p>In MVC 1.0 it was possible to get the context statically by casting the current <code>IHttpHandler</code>:</p>
  
  <pre><code> var context = ((MvcHandler) HttpContext.Current.CurrentHandler).RequestContext;
  </code></pre>
  
  <p>Now the project has been upgraded to MVC 2.0 and this exception is thrown on the cast:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'ServerExecuteHttpHandlerWrapper' to type 'System.Web.Mvc.MvcHandler'.</p>
  </blockquote>
  
  <p>I'm not sure if it's relevant but this is being run in .NET 4.0 on IIS6.</p>