问题
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