我尝试使用 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>
我还听说,在项目属性中,您应该启用 Windows 身份验证并禁用匿名身份验证,如下所示:
但随后我在 Chrome 中遇到了重定向循环,并显示消息“此网页有重定向循环”。
我还检查了我的计算机上是否安装了 Windows 身份验证:
关于如何解决这个问题有什么想法吗?
非常感谢
最佳答案
当我有:
<authentication mode="Windows"/>
<identity impersonate="true/>
在 web.config 中,我通过以下方式获取当前用户:
string currUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
关于asp.net - HttpContext.Current.User.Identity.Name 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080348/