Asp.net mvc 3 无法获取当前用户

Asp.net mvc 3 无法获取当前用户,asp.net-mvc-3,controller,Asp.net Mvc 3,Controller,我一直在寻找这一个很长时间,发现了许多链接,但没有一个有效 当我在webforms中工作时,我能够通过以下代码获得当前用户 System.Security.Principal.IIdentity identity = HttpContext.Current.User.Identity; string user = identity.Name; 但在mvc项目中,current不起作用,所以我尝试了它 HttpContext.User.Identity 当我写identity.name时,

我一直在寻找这一个很长时间,发现了许多链接,但没有一个有效

当我在webforms中工作时,我能够通过以下代码获得当前用户

System.Security.Principal.IIdentity identity = HttpContext.Current.User.Identity;
 string user = identity.Name;
但在mvc项目中,current不起作用,所以我尝试了它

HttpContext.User.Identity 
当我写identity.name时,它一次又一次地变为null

我正在尝试获取当前登录windows用户的用户名。我怎样才能得到它。

从控制器上,您可以直接尝试-

string user = User.Identity.Name;

您是否试图在控制器操作方法中执行此操作?您是否尝试过User.Identity.Name;是的,我正在用一个动作方法访问它,但它一直是空的。你在配置文件中指定了吗?你没有给一个当天试图帮助你的人任何回复,并且在3周后对他的努力投了反对票?凉的