Get newly created member's ProviderUserKey
I've got this line which works perfectly:
// MembershipCreateStatus
var createStatus = Membe开发者_StackOverflow中文版rshipService.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
.
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
精彩评论