【发布时间】:2012-08-14 09:27:09
【问题描述】:
在一个使用表单身份验证的mvc .net web应用程序中,如何知道控制器中当前的用户身份?
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-3
在一个使用表单身份验证的mvc .net web应用程序中,如何知道控制器中当前的用户身份?
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-3
你可以使用User.Identity.Name:
[Authorize]
public ActionResult SomeAction()
{
string currentlyLoggedInUsername = User.Identity.Name;
...
}
【讨论】:
this.HttpContext.User.Identity
请注意,您还应该检查是否
this.HttpContext.User.Identity.IsAuthenticated
区分匿名用户和经过身份验证的用户。
【讨论】: