C# 如何在ASP.NET5上获取当前windows用户?
我正在尝试在新的ASP.NET5中获取当前windows用户 从Visual Studio运行时会正确返回,将其部署到服务器时会返回应用程序池标识:C# 如何在ASP.NET5上获取当前windows用户?,c#,asp.net,C#,Asp.net,我正在尝试在新的ASP.NET5中获取当前windows用户 从Visual Studio运行时会正确返回,将其部署到服务器时会返回应用程序池标识: string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 这将返回空字符串: string name = System.Threading.Thread.CurrentPrincipal.Identity.Name; 这已在bew ASP版本中删除: H
string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
这将返回空字符串:
string name = System.Threading.Thread.CurrentPrincipal.Identity.Name;
这已在bew ASP版本中删除:
HttpContext.Current.User.Identity
非常感谢您的帮助。您没有指定要从何处获取此信息,但可以从控制器中以
User.Identity.Name
的形式获取此信息:
public IActionResult Index()
{
ViewData["Message"] = $"Hello, {User.Identity.Name}";
return View();
}
这将导致“你好,桌面电脑\用户”。您也可以在视图中执行此操作。您将获得应用程序池标识,因为它是您的进程执行所使用的帐户。如果您需要拨打电话的用户的身份,则需要使用模拟
您可以将
添加到web.config,也可以使用IIS管理器避免直接编辑web.config;选择您的网站,单击“身份验证”并启用ASP.NET模拟。您使用的身份验证模式是什么
如果您有以下设置
- 身份验证模式=Windows
- 应用中的模拟
- IIS网站上已禁用匿名访问
string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
ASP.Net 5中不存在Web.config,并且我在IIS管理器中未看到模拟选项。我是否在ASP.Net 5中设置模拟?