title: IRouteHandler in Web Forms: Routing requests that require HttpContext.User
body: <p>I'm trying to add a pretty basic route to an Asp.Net Web Forms app (running under IIS 7, integrated mode): for requests coming to <a href="http://mydomain.com/foo/" rel="nofollow noreferrer">http://mydomain.com/foo/</a> I would like to show the results of a dynamic page (<a href="http://mydomain.com/foopage.aspx" rel="nofollow noreferrer">http://mydomain.com/foopage.aspx</a>).</p>
  
  <p>I've created a RouteHandler that does all this and it seems to be routing correctly.</p>
  
  <pre><code>    public IHttpHandler GetHttpHandler(RequestContext requestContext)
      {
       var page = System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath("~/foo.aspx", typeof(MyApp.Web.Foo)) as MyApp.Web.Foo;
       return page as IHttpHandler;
      }
  </code></pre>
  
  <p>The problem is, inside my RouteHandler's GetHttpHandler method, all the instances of the current user (requestContext.HttpContext.User, System.Web.HttpContext.Current.User) are null.  Sadly, foo.aspx needs to know what the current user is (for login controls, role stuff, etc), so rendering the page is throwing null reference exceptions.  My guess is that these route handlers are firing off before Asp.Net gets the chance to wire up the HttpContext with user info.  Any idea of a work-around?</p>
  
  <p>PS - I realize this can be accomplished by doing a Server.Transfer in a page at <a href="http://mydomain.com/foo/default.aspx" rel="nofollow noreferrer">http://mydomain.com/foo/default.aspx</a>.  I'd like to use routing for this sort of thing rather than having a bunch of useless folders cluttering things up.</p>
  
  <p>Thanks!</p>