Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Oct 18, 2017 @ 04:27
    Tom
    0

    Rest Extension in Umbraco 7.6 HttpContext.Current.User is returning umbraco user not current member?

    We're using Active Directory for membership and in a Rest Extension when calling HttpContext.Current.User it is returning the currently logged in umbraco user rather than the currently logged in member..

    I was wondering if anyone else had experienced this?

    in a razor view using @Membership.GetUser().UserName it returns the logged in member

    if I do this in code:

    [RestExtension("InductionHelper")]
    public class InductionHelper
    {
        [RestExtensionMethod(ReturnXml = false, AllowAll = true)]
        public static string RegisterPolicyAgreement()
        {
            var memberName = Membership.GetUser().UserName;
            var someRandomVarName = ApplicationContext.Current.Services.MemberService.GetByUsername(memberName);
    

    Membership.GetUser() is querying based on the currently logged in umbraco admin user in our override of get user:

    public class CustomMembershipProvider : ActiveDirectoryMembershipProvider
    {
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if (!string.IsNullOrWhiteSpace(username))
            {
                var result = (MembershipUser)HttpContext.Current.Session[username];
    
                if (result == null)
                {
                    result = base.GetUser(username, userIsOnline);
    
                    HttpContext.Current.Session[username] = result;
                    HttpContext.Current.Session["recentUser"] = username;
                }
    
                return result;
            }
            else
            {
                return null;
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft