Reputation: 859
probabaly a daft question but when creating a user using .net membership, can i exclude the username and just have the email as the 'username' like this?
Membership.CreateUser(model.UserName, model.Password, model.Email, ....
or leave blank...
Membership.CreateUser("", model.Password, model.Email, ......
cheers
Upvotes: 1
Views: 581
Reputation: 1857
What I have done in this case is generate a random username upon account creation. Then, when it comes time to log them in, call Membership.GetUserNameByEmail(emailAddress) to get the username and use that to log them in.
I didn't want to put the email address into the username field due to users occasionally changing their email addresses.
Upvotes: 2
Reputation: 32936
if you want the email as the username why not:
Membership.CreateUser(model.Email, model.Password, model.Email, ....
I'm not sure if an empty string for the username will be allowed (try it and see?) the docs are not clear, but as the docs state that a reason for failure can be MembershipCreateStatus.DuplicateUserName
, you may only be allowed a single user with a blank name anyway...
Upvotes: 3