Once the Membership API has been configured, we can use the Web Site Administration Tool to manually create users and roles. But more importantly, we can invoke the Membership API from code :
string password = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, Membership.MinRequiredNonAlphanumericCharacters
MembershipUser membershipUser = Membership.CreateUser(userName, password, emailAddress);
Roles.AddUserToRole(userName, "Member");
The following shortcut is also provided to obtain the Membership API user whose username matches the one obtained from the Forms Authentication cookie :
MembershipUser currentUser = Membership.GetUser();
Guid userID = (Guid)currentUser.ProviderUserKey;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment