howto get the user id from a FormsAuthentication p

2019-09-12 04:39发布

问题:

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...
}