David Murdoch
David Murdoch

Reputation: 89332

Get newly created member's ProviderUserKey

I've got this line which works perfectly:

// MembershipCreateStatus
var createStatus = MembershipService.CreateUser(model.Email, model.Password);

Now I want to get the ProviderUserKey of the member that was just created. What is the easiest way to do this?

I would absolutely LOVE something like this:

MembershipUser member;
// create a new user and return the status and the member (if created).
var createStatus = MembershipService.CreateUser(model.Email, model.Password, out member);

But I'll settle for the just getting the ProviderUserKey.

Upvotes: 1

Views: 1639

Answers (1)

Shan Plourde
Shan Plourde

Reputation: 8726

Can you use the provider specific API instead? If so, you should be able to do this. Typically the provider APIs return your new MembershipUser instance, and just have the status as an out parameter to the CreateUser() method.

The Membership.CreateUser() API returns a MembershipUser instance, see http://msdn.microsoft.com/en-us/library/d8t4h2es.aspx. You can then get the ProviderUserKey as such:

MembershipUser newUser = MembershipService.CreateUser(email, password, etc.);
newUser.ProviderUserKey

Upvotes: 1

Related Questions