更新时间:2023-12-03 19:38:46
这可能有效,
string userId = Membership.GetUser( userName)。ProviderOserKey.ToString(); // 在GetUser中传递您的姓名。
-KR
GetUser
返回null
,或ProviderUserKey
。您没有测试其中任何一个,看看它们是否返回null
。最后,您尝试在null
上调用.ToString()
。这就是你收到错误信息的原因。
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.
if (Membership.ValidateUser(txt_email.Text, txt_password.Text))
{
string userId = Membership.GetUser().ProviderUserKey.ToString();
}
Any possible reasons????
This might work,string userId = Membership.GetUser("userName").ProviderUserKey.ToString(); // pass your name in GetUser.
-KR
EitherGetUser
returnednull
, orProviderUserKey
did. You didn't test either of these to see if they returnednull
. In the end, you tried to call.ToString()
onnull
. That's why you got the error message you did.