Copied to clipboard

Flag this post as spam?

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


  • Ian 23 posts 113 karma points
    Jul 13, 2016 @ 12:31
    Ian
    0

    IsMemberAuthorized throwing NullReferenceException

    Hi all, Im getting a strange ysod when running some code which previously worked.

    IsMemberAuthorized is throwing a NullReferenceException.

    The code (in a view) looks like this:

    bool memberIsLoggedIn = Umbraco.MemberIsLoggedOn();
    bool memberIsLoggedInAsHcp = Members.IsMemberAuthorized(
        allowTypes: new List<string>() { "HealthcareProfessional" });
    

    The stack trace is:

    [NullReferenceException: Object reference not set to an instance of an object.]
    Umbraco.Web.Security.MembershipHelper.IsMemberAuthorized(Boolean allowAll, IEnumerable'1 allowTypes, IEnumerable'1 allowGroups, IEnumerable`1 allowMembers) +208
    ASP.PageViewsPartialsNavbarcshtml.Execute() in c:\Development\x.Umbraco\x.Umbraco.Web\Views\Partials_Navbar.cshtml:54

    The memberIsLoggedIn var gets set to true.

    I say it was working previously - all I have done is added a new member group without touching the existing "HealthcareProfessional" group, and rebuilt the site.

    Using umbraco v7.4.1

    Anyone seen this or have any ideas?

  • Ian 23 posts 113 karma points
    Jul 13, 2016 @ 20:52
    Ian
    0

    Ok I think I worked out why this is happening, so just fyi for anyone else finding this thread:

    The member had previously been logged in and everything had been working. However, someone had deleted the member in the backoffice and this is what caused the ysod.

    Now because my browser tab still had the forms auth cookie in place, when I hit F5 the Umbraco.MemberIsLoggedOn() returned true. My guess is that that method simply works off the presence of the forms auth cookie.

    And I'm guessing that any null-ref guard code inside IsMemberAuthorized also uses that and then assumes there is a 'current member'. Hence the null ref.

    Recycling the app pool didnt fix the error. Only removing the forms auth cookie did.

    I could download the source and go through it but unfortunately I dont have the time atm. Maybe Ill revisit it.

    Hope the above helps someone with the same problem.

Please Sign in or register to post replies

Write your reply to:

Draft