加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – HttpContext.Current.User.Identity.Name为null

发布时间:2020-12-16 09:11:53 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试使用HttpContext.Current.User.Identity.Name从内部网络获取用户的 Windows登录详细信息,但它是空的. 我已经尝试在Web.Config中更改身份验证模式,但没有任何乐趣: system.web authentication mode="Windows" / compilation debug="true" targetFr
我正在尝试使用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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读