aspnet_Users table: Adding unique constraint on UserName?

Last post 05-15-2008 2:29 AM by yasserzaid. 2 replies.

Sort Posts:

  • aspnet_Users table: Adding unique constraint on UserName?

    05-14-2008, 5:11 PM
    • Loading...
    • tmpuzer
    • Joined on 03-07-2008, 5:45 PM
    • Posts 299

    Do you think there would be any harm in adding a unique constraint on the UserName column in the aspnet_Users table?  I don't think I have any use for the ApplicationId so I'd just prefer to have user names be unique as opposed to having just the ApplicationId/UserName combination be unique?  Thoughts?

    Also, what would the syntax be for adding this unique constraint in SQL server? 

    If a post helps me I'll always eventually mark it as an answer. But I frequently don't mark it right away because I feel once a thread is marked as answered, discussion tends to end. And I like to discuss things a bit.
  • Re: aspnet_Users table: Adding unique constraint on UserName?

    05-14-2008, 5:23 PM
    Answer
    • Loading...
    • Joël Hébert
    • Joined on 07-20-2005, 6:07 PM
    • Ottawa Canada
    • Posts 597

    cant you simply use the createuserwizard control, it checks to see if the username allready exists?

    you dont need a constraint...if you use the control

    Joël Hébert

    ASP.NET Consultant
    Opulent ASP Development Inc.
    www.opulentasp.com
    Ottawa,Canada

    Click "Mark as Answer" on the posts that helped you to help future readers to get the solutions
  • Re: aspnet_Users table: Adding unique constraint on UserName?

    05-15-2008, 2:29 AM
    Answer

    Hi,

    Try this

    Two methods to check UserName and Email availability

     

     //-- method to check Email availability
        public bool CheckEmail()
        {
            bool emailExsit = false;
            MembershipUserCollection users = Membership.FindUsersByEmail(Email.Text);
            foreach (MembershipUser user in users)
            {
                if (Email.Text == user.Email)
                {
                    emailExsit = true;
                    break;
                }
                else
                {
                    emailExsit = false;
                }
            }
            return emailExsit;
    
        }
    
        //-- method to check user name availability
        public bool CheckUserName()
        {
            bool userExsits = false;
            MembershipUserCollection users = Membership.FindUsersByName(UserName.Text);
            foreach (MembershipUser user in users)
            {
                if (UserName.Text == user.UserName)
                {
                    userExsits = true;
                    break;
                }
                else
                {
                    userExsits = false;
                }
            }
            return userExsits;
        }
     
    Regards,
    Yasser Zaid

    ~ Please remember to click Mark as Answer on this post if it helped you ~
Page 1 of 1 (3 items)