IRouteHandler in Web Forms: Routing Requests Requiring HttpContext.User

I am trying to add a fairly simple route to an Asp.Net Web Forms application (works under IIS 7, integrated mode): for requests coming into http://mydomain.com/foo/ I would like to show the results of a dynamic page ( http: // mydomain.com/foopage.aspx ).

I created a RouteHandler that does all of this and seems to be routed correctly.

    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;
    }

      

The problem is that inside my RouteHandler GetHttpHandler method, all instances of the current user (requestContext.HttpContext.User, System.Web.HttpContext.Current.User) are null. Unfortunately foo.aspx needs to know what the current user is (for login controls, roles, and so on), so rendering the page throws unnecessary reference exceptions. My guess is that these route handlers get fired before Asp.Net gets a chance to bind the HttpContext to user information. Any idea for a workaround?

PS - I understand that this can be done by executing Server.Transfer at http://mydomain.com/foo/default.aspx . I would like to use routing for this kind of thing, and not have empty useless folders cluttering things up.

Thank!

+2


source to share


2 answers


I managed to figure it out.

Like this question , my routes worked fine when the route origin ended in .aspx ( http://mydomain.com/foo-origin.aspx ) but failed when they didn't ( http://mydomain.com/ foo-origin / ).

The MSDN article on Configuring Routing with Web Forms talks about making a few changes to the web config, but doesn't account for what you need to set runAllManagedModulesForAllRequests to true in node modules:



<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
  </system.webServer>
</configuration>

      

Now it works smoothly.

0


source


See the answer to this question very similar.



0


source







All Articles