1

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.

David Murdoch
  • 87,823
  • 39
  • 148
  • 191

1 Answers1

1

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
Shan Plourde
  • 8,528
  • 2
  • 29
  • 42
  • Also see http://msdn.microsoft.com/en-us/library/system.web.security.membership.provider.aspx for details on how to get the default MembershipProvider for your application. – Shan Plourde Feb 09 '11 at 21:20
  • I'll try this in a bit. How could I go about getting the `CreateStatus`? – David Murdoch Feb 09 '11 at 21:28
  • It's an out parameter in the MembershipProvider.CreateUser API, http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.createuser.aspx – Shan Plourde Feb 09 '11 at 21:31