HttpContext.Current.User.Identity.Name为null

Nic*_*ick 3 asp.net asp.net-mvc httpcontext

我正在尝试使用HttpContext.Current.User.Identity.Name从内部网络获取用户的Windows登录详细信息,但它是空的.

我已经尝试在Web.Config中更改身份验证模式,但没有任何乐趣:

  <system.web>
    <authentication mode="Windows" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
Run Code Online (Sandbox Code Playgroud)

我还听说在项目属性中你应该启用Windows身份验证并禁用匿名身份验证,如下所示:

在此输入图像描述

但后来我得到了一个重定向循环,在Chrome中显示"此网页有重定向循环"的消息.

我还检查过我的机器上安装了Windows身份验证:

在此输入图像描述

有关如何解决此问题的任何想法吗?

非常感谢

Mar*_*rse 7

当我有:

<authentication mode="Windows"/>
<identity impersonate="true/>
Run Code Online (Sandbox Code Playgroud)

在web.config中我得到当前用户:

string currUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
Run Code Online (Sandbox Code Playgroud)