Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niels Hartvig 1951 posts 2391 karma points c-trib
    May 17, 2010 @ 16:06
    Niels Hartvig
    0

    HttpContext.User is null in /base httpmodule

    I'm currently debugging a bug in /base (Umbraco v4.0.3) where the User object (HttpContext.Current.User) of the current httpcontext is null in the /base httpmodule but not null when an Umbraco page is rendered on the same site. This means that the Membership Provider checking in /base obviously fails as the internal check in Umbraco is checking for HttpContext.Current.User.Identity.IsAuthenticated which then cast an exception (obviously because User is null).

    I can't get around my head why that is - am I missing something obvious (yes - but what ;-))?

  • Lasse Eskildsen 34 posts 57 karma points
    May 17, 2010 @ 16:09
    Lasse Eskildsen
    0

    Is it an async request to /base? If so, that's your problem.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    May 17, 2010 @ 16:40
    Morten Bock
    0

    I think the fix is in this branch:

    http://umbraco.codeplex.com/SourceControl/changeset/view/66135#904813

    The magic lies in inheriting from the IRequiresSessionState interface also, I think. Try and do a compare of the files?

  • webmonger 130 posts 285 karma points
    May 17, 2010 @ 16:42
    webmonger
    1

    The problem is due to the request being actioned to early in the asp.net page life cycle as far as we could tell.

    The issues OnBeginRequest did not have a member avaiable at that time.

    We got around the issue by creating a different handler so it went through the full page life cycle before trying to request Member.

    public class CustomRestHandler: IHttpHandler, IReadOnlySessionState 
    {
    public void ProcessRequest(HttpContext context)
    {
    // Do stuff here
    }
    }

    Hope that helps

    Jon

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    May 18, 2010 @ 10:21
    Niels Hartvig
    0

    Thanks for the help all. Turns out that it was a combination of things that caused the stir. The most significant was of course moving the processing to the PostAuthorizeRequest event.

    Still I wasted a couple of stupid hours by not realizing that I didn't append ".aspx" to the url I was using for testing. Base was still invoked but because the module wasn't run as managed, no authorization was going on in .NET (ie. Httpcontext.User was null). Appending ".aspx" did the trick and so did appending runAllManagedModulesForAllRequests="True" to the modules element in web.config (I'm running on IIS7). Of course I could have read the manual.

    However a big benefit from all of this was that /base has been re-written to use the internal member methods of Umbraco instead of its own which means full support for MembershipProvider auth (however still only umbraco members). For 4.1 I'll update to support all types of membershipProviders/roles.

    Thanks all. Now 4.0.4 is close :)

  • Karl Walker 10 posts 30 karma points
    Oct 08, 2010 @ 15:23
    Karl Walker
    0

    Niels, has this been fixed in 4.5.2 (if its a bug at all, perhaps just configuration issue)?

    I did what you suggested and it works, so thanks

Please Sign in or register to post replies

Write your reply to:

Draft