在表单模型中,我曾经通过以下方式获取当前登录用户:
Page.CurrentUser
如何在ASP中获得控制器类中的当前用户。净MVC吗?
在表单模型中,我曾经通过以下方式获取当前登录用户:
Page.CurrentUser
如何在ASP中获得控制器类中的当前用户。净MVC吗?
当前回答
我发现User工作,即User. identity . name或User. isinrole(“管理员”)。
其他回答
使用System.Security.Principal.WindowsIdentity.GetCurrent () . name。
这将获取当前登录的Windows用户。
这个页面可能就是你要找的: 在MVC3中使用Page.User.Identity.Name
你只需要User.Identity.Name。
IPrincipal currentUser = HttpContext.Current.User;
bool writeEnable = currentUser.IsInRole("Administrator") ||
...
currentUser.IsInRole("Operator");
我使用:
Membership.GetUser().UserName
我不确定这是否适用于ASP。NET MVC,但它值得一试:)
HttpContext.Current.User试试。
公共共享财产当前()作为 System.Web.HttpContext System.Web.HttpContext的成员 简介: 获取或设置当前HTTP请求的System.Web.HttpContext对象。 返回值: 当前的System.Web.HttpContext HTTP请求