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

标签 asp.net windows-identity

我正在使用HttpContext.Current.User.Identity.Name来获取使用Web应用程序时的用户名。在开发过程中,我使用的是本地iis,并启用了集成的Windows身份验证,并且启用和禁用了匿名访问,并且能够获取用户名。

现在,当我发布Web应用程序时,它恢复为空白。发布的服务器上的设置是相同的,并且我尝试使用Page.User.Identity.Name,它也返回空白。

有谁知道这是为什么以及如何解决?

最佳答案

您可能同时具有匿名身份验证和Windows身份验证。关闭匿名关闭。

所以,

<system.web>
    <authentication mode="Windows" />
</system.web>


在该应用程序的IIS配置中,
在“身份验证”标签中查看

Set **Anonymous Authentication** to **Disabled** and
Set **Windows Authentication** to **Enabled**


这应该可以正常工作,并且Identity.UserName现在应该正确显示。

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

相关文章:

c# - .NET Framework 4.6.1 的 Web.Config 版本

asp.net - 如何控制对 ASP.Net MVC 3 View 上的表单字段的访问?

c# WindowsIdentity 模拟不工作

c# - 列出用户具有读取权限的文件 (ASP.NET)

c# - 验证文件上传大小限制的所有地方是什么?

asp.net - 将 Linq 转换为 SQL

c# - 代码访问安全策略问题 - 将第三方 dll 部署到 bin

authentication - 如何使用 Windows 身份验证和自定义角色提供程序设置 OWIN

c# - WindowsIdentity 构造函数使用 LogonUser 的 token 引发异常

asp.net - 为什么启用模拟后 Thread.CurrentPrincipal.Identity 和 WindowsIdentity.GetCurrent() 会有所不同?