问题
I am getting user.identity.name
empty in web application using forms authentication after authenticating through memberships.
I redirect it to other form but how to keep track of which user is logged in, i am not using session. Is there another way?
MembershipUser oCurrentUser = Membership.GetUser();
Response.Write(oCurrentUser.UserName);
In this also it is giving me nullreference exception
,though it is validating properly
bCheckUser = Membership.ValidateUser(txtUserName.Text, txtPassword.Text);
this is returning true.
回答1:
Have a look at FormsAuthentication.SetAuthCookie()
Once Membership.ValidateUser()
is true you should set the authentication ticket
(using FormsAuthentication.SetAuthCookie) and then you'll be able to get the User.Identity
object on any other page.
来源:https://stackoverflow.com/questions/5556970/user-identity-name-is-empty