User.identity .name is empty

那年仲夏 提交于 2019-12-13 17:42:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!