如何从IIS检索当前登录的用户ID

时间:2013-09-18 20:44:30

标签: 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.ToString();

AuthenticateUser(name)
}

我总是得到“name”的空值。我的web.config文件是:

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

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

1 个答案:

答案 0 :(得分:0)

尝试让用户不是来自HttpContext而是来自Controller

Controller.User.Identity.NameUser.Identity.Name