Verify user exits

Hi Experts.

I"ve been searching forever and can't seem to find out how to verify that a user exists in asp.net 2.0
 I'm using the Authorization/Membership Management and c#

Tahnks!
tenderroni992003Asked:
Who is Participating?
 
guru_samiCommented:
If you are using ASP.Net Membership here is one way to find if a UserExists or not.
Below is sample code:
You can check othe Membership API methods to see if any other matches your requirements.
Also the is Roles API you might want to look into if you want to deal with Roles.


 MembershipUser user = Membership.GetUser("YourUserName");
        if (user != null)
        {
            Response.Write(user.UserName);
       }
        else
       {
         Response.Write("User is null");
        }

Open in new window

0
 
tenderroni992003Author Commented:
I tried the above solution, and it always returns null.


admin: relevance:  asp.net 2.0, c#,  microsoft programming

0
 
guru_samiCommented:
make sure your membership is working properly.
i.e. Are you able to create new user and login with that username?
Please provide more info on what exactly you did and what exactly you are looking for.
0
 
tenderroni992003Author Commented:
guro_sami, your solution was absolutely correct!  Thank you!

I fond my error.  I was getting the string from a text box, but I wasn't converting the textbox text to a string.  I thought that you could stop at textbox.Text, but you actually have to have
textbox.Text.ToString().  
so the following works:  Membership.GetUser(textbox.Text.ToString())
Go figure.

Thank you so much!

 
0
 
tenderroni992003Author Commented:
Thank yo so much for all of your wonderful help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.