howto get the user id from a FormsAuthentication page in asp.net MVC?

强颜欢笑 提交于 2019-12-13 08:47:44

问题


i made a webpage which use FormsAuthentication. now i need to get the user id of the user (if a user is logged in)

how to get these? i tryed to access it via the FormsAuthentication but there is no method liks: getUserId()

any solutions? by the way, i need the id in my controller not in my view.


回答1:


if (HttpContext.Current.User.Identity.IsAuthenticated)
{
    var id = HttpContext.Current.User.Identity.Name;
    // Do stuf...
}


来源:https://stackoverflow.com/questions/11134818/howto-get-the-user-id-from-a-formsauthentication-page-in-asp-net-mvc

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