These docs are for v20.3.44. Click to read the latest docs for v20.3.186.

Discussions

Ask a Question
Back to All

Get login name of on behalf of user

Is there a c# method to get the login name of the person you are on behalf of? We have an asfx ipart that we are trying to make work with on behalf of mode, and essentially it adds some products to the on behalf of person's cart. However, what we are seeing instead is that it adds it on to the logged in user's cart instead.

I believe the issue has something to do with how the user is initialized with the iPart as indicated from the code below. Any suggestions?

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!IsPostBack)
        {
            OneTimeInitializations();
            LoadStates();
        }
        if (Asi.Security.AppPrincipal.CurrentIdentity.IsAuthenticated && Asi.Security.AppPrincipal.CurrentIdentity.LoginIdentity != "")
        {

            iMISID = Asi.Security.Utility.SecurityHelper.GetOnBehalfOfUser(); 
            Asi.iBO.IiMISUser user1 = (Asi.iBO.IiMISUser)Session["LoginUser"]; 
            if (user1 == null)
            {

                user1 = Asi.iBO.ContactManagement.CContactUser.LoginByWebLogin(Asi.Security.AppPrincipal.CurrentIdentity.LoginName);

            }
            CContact CurrentUser = new CContact(user1, iMISID);
            Asi.iBO.ContentManagement.CWebUser user =
                    Asi.iBO.ContentManagement.CWebUser.LoginByPrincipal(HttpContext.Current.User);
            PartyData person = MembershipManager.FindPartyByPartyId(user.ContactId);

Thanks,

Julie