gpt4 book ai didi

asp.net - 为什么 HttpContext.Current.User.Identity.Name 返回空白

转载 作者:行者123 更新时间:2023-12-02 16:17:03 28 4
gpt4 key购买 nike

我创建了一个网站。这是一个内部站点。这是一个 .NET 4.0 站点。我想使用浏览该网站的人的 HttpContext.Current.User.Identity.Name 获取用户名。由于它是内部的,因此没有登录页面。我不确定我错过了什么。我的网络配置中是否需要以下内容:

<authentication mode="Windows"></authentication>
<identity impersonate="true"/>
<authorization>
<allow users="?"/>
</authorization>

还有这个:

  <system.webServer>
<validation validateIntegratedModeConfiguration="false" />

最佳答案

未经身份验证时显示为空白。您还可以通过执行以下操作来验证这一点:

HttpContext.Current.User.Identity.IsAuthenticated

检查您在 IIS 中的身份验证级别,是否也设置为启用 Windows 身份验证?

关于asp.net - 为什么 HttpContext.Current.User.Identity.Name 返回空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839567/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com