【发布时间】:2023-04-10 07:50:02
【问题描述】:
我遇到了 Windows 身份验证问题。我使用命令“dotnet new webapp --auth Windows”创建了一个新的网络应用程序。这应该有一个到目前为止与模板一起工作的 Windows 身份验证。现在我想使用 Windows 用户名。在 Razor 页面 (.cshtml) 上,我可以使用 @User.Identity.Name 毫无问题地访问用户名。如何访问 (.cshtml.cs) 文件中的用户名。
进行了以下尝试:
Enviroment.UserName --> 在本地机器上可以正常工作,但在 IIS 上不行。
User.Identity.Name - 当前上下文中不存在名称“用户”
HttpContext.Current.User.Identity.Name
HttpContext.Current.User - 当前上下文中不存在名称“HttpContext”
System.Security.Principal.WindowsIdentity.GetCurrent().Name
我的应用程序将在启用 Windows 身份验证的 Windows Server 上的 IIS 上运行。
我希望有人可以帮助我。提前感谢您,祝您有愉快的一天
【问题讨论】:
标签: c# asp.net razor windows-authentication razor-pages