Asp.net mvc 4 如何从IIS检索当前登录的用户id

Asp.net mvc 4 如何从IIS检索当前登录的用户id,asp.net-mvc-4,authentication,iis,windows-authentication,Asp.net Mvc 4,Authentication,Iis,Windows Authentication,我需要在IIS中检索当前登录的用户ID,然后将该ID传递给函数以进行身份验证 public ActionResult Login(myLoginModel model) { System.Security.Principal.IPrincipal user; user = System.Web.HttpContext.Current.User; String name = user.Identity.Name.ToStrin

我需要在IIS中检索当前登录的用户ID,然后将该ID传递给函数以进行身份验证

public ActionResult Login(myLoginModel model)
{
            System.Security.Principal.IPrincipal user;
            user = System.Web.HttpContext.Current.User;
            String name = user.Identity.Name.ToString();

AuthenticateUser(name)
}
“name”的值总是为空。我的web.config文件是:

  <authentication mode="Windows"/>
    <identity impersonate="true"/>


我在IIS管理器上禁用了匿名身份验证并启用了Windows身份验证。你能帮我解决这个问题吗

尝试不从
HttpContext
而是直接从
Controller
获取用户:


Controller.User.Identity.Name
或只是
User.Identity.Name

可能的重复--还有,FWIW,当他们点击“登录”时,他们已经从广告中获得了身份验证(除非你正在做一些基本身份验证之外的事情--这可能会在
会话\u Start
中发生)我尝试放置[authorize]在我的控制器方法之上,但它不起作用。