SaaS CMS has officially launched! Learn more now.

How can I get MembershipUser from the PrincipalInfo.CurrentPrincipal.GetUserGuid

Vote:
 

Hi,

I need to get the membership user and I have the EPiServer.Security.PrincipalInfo.CurrentPrincipal.GetUserGuid() in a variable. 

I tried Membership

Membership.GetUser(guidVariable);

but it returns null, since the GetUserGuid property is not the membership GUID.

After a lot of searches, I came up with this code:
Mediachase.Commerce.Customers.CustomerContext customerContext = new Mediachase.Commerce.Customers.CustomerContext();
Mediachase.Commerce.Customers.CustomerContact userContact = customerContext.GetContactById(modifierId);
return Membership.GetUser(userContact.ProviderUserKey.ToString());

which simes to work but
ProviderUserKey is Obsolete.

What shall I do?

Thanks in advance,

Ashkan
#142240
Dec 07, 2015 10:14
Vote:
 

Hi,

You can use userContact.PrimaryKeyId instad. 

/Q

#142245
Dec 07, 2015 13:30
Vote:
 

Hi Quan,

Thanks for the reply. 

Unfortunately, the userContact.PrimaryKeyId does not contain the "username" nor the membershipGUID.  It is completely the same as the value that I had originally (from CurrentPrincipal.GetUserGuid), So I can't use it to retrieve data from Membership.

It is the GUID of the episerver contact, not the membership.

#142246
Dec 07, 2015 14:02
Vote:
 

Can you try with CustomerContext.GetUserForContactId(PrimaryKeyId) to see if it works for you?

(Btw- mentioning the version in your post will be a big help ;) )

/Q

#142247
Dec 07, 2015 14:07
Vote:
 
<p>Hi Quan,</p> <p>Thanks again for the reply&nbsp;and sorry that I didn't mention my EPIServer version (which by the way is 8.11.0.0).</p> <p>The method you mentioned was the one that I needed.</p> <p></p> <p>Thanks again&nbsp;</p> <p>Best Regards,</p> <p>Ashkan</p>
#142248
Dec 07, 2015 14:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.