Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After customer validation i want to retrieve his user id.. I am using below code for that but it is giving error : Object reference not set to an instance of an object.

C#
if (Membership.ValidateUser(txt_email.Text, txt_password.Text))
            {

                string userId = Membership.GetUser().ProviderUserKey.ToString();
            }


Any possible reasons????
Posted

This might work,
C#
string userId = Membership.GetUser("userName").ProviderUserKey.ToString(); // pass your name in GetUser.


-KR
 
Share this answer
 
Either GetUser returned null, or ProviderUserKey did. You didn't test either of these to see if they returned null. In the end, you tried to call .ToString() on null. That's why you got the error message you did.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900