SaaS CMS has officially launched! Learn more now.

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



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

I tried Membership


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,

Dec 07, 2015 10:14


You can use userContact.PrimaryKeyId instad. 


Dec 07, 2015 13:30

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.

Dec 07, 2015 14:02

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 ;) )


Dec 07, 2015 14:07
<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</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>
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.