asp.net-mvc - User.Identity.Name 给出 IIS 服务器用户名而不是客户端用户名
问题描述
在我的 MVC 应用程序中,我试图在右上角显示域/用户,它在带有 User.Identity.Name / Request.LogonUserIdentity.Name 的 Visual Studio 上运行良好
当我在服务器上托管它时,它显示 server_domain/server_username。
我已经将身份验证模式 = windows 并模拟为 true。使用 ApplicationPoolIdentity 和 LoadUserProfile = true。
我知道我需要关闭匿名并打开 Windows 身份。我已经做到了。我还编辑了我的 applicationHost.config 并使覆盖允许身份验证模式。我已经在同一个文件中删除了两者的锁定。
我的本地域和服务器域是不同的。
我不明白我错过了什么/做错了什么。有人可以帮我吗?
解决方案
您可以使用HttpContext.User.Identity.Name
获取客户端用户名。
另外,请确保您在 web.config 中的 system.web 中有授权标签
<authorization>
<allow users="?" />
</authorization>
https://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net/
推荐阅读
- django - 如何在 Django 管理操作中使用 queryset.update?
- php - 嵌套 Do... While 循环矩形 PHP
- python - 将 .wav 读取为字节
- javascript - 检测到 Puppeteer 可能的 EventEmitter 内存泄漏。11 个退出侦听器添加到 [进程]
- python - 用于 bash 脚本的 Loguru 设置,用于与多个 Python 脚本一起使用
- python - 无法访问 JSON 属性
- javascript - 选择数据过滤器时如何显示项目
- java - Spring Data JPA:根据使用的 ManyToOne 字段过滤数据
- ios - 无法验证开发人员完整性,iOS 企业版
- asp.net-mvc - 提交按钮发送空白(无数据)数据 MVC ASP.Net