简体   繁体   中英

Check if a username has been registered

I am using the builtin ASP.NET logon and user management features. Is there a way to just identify if a username or email address is already registered? I would've thought it's part of FormsAuthentication or similar, but can't find such a function.

Check whether Membership.GetUser method returns a null value or not.

If you want to create a new user and you're doing this check as a part of that process, try calling Membership.CreateUser method and check the MembershipCreateStatus to get the failure reason, in case it fails.

The only correct way to do this is to actually try to register/create the user right away and handle the results of that action. You don't have to enable the new user until they actually finish the registration process and can delete the account if they abandon your site before completing it, but anything else you do opens yourself up to a race condition bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM