在.NET Core控制台应用程序中(请注意:不是ASP.NET Core!),如何获得当前用户?明确地说,我正在寻找以前不存在的Thread.CurrentPrincipal。
PlatformServices不包含此信息,环境也不包含。
最佳答案
得到它了。可能的选择是使用WindowsIdentity:
WindowsIdentity.GetCurrent().Name
有必要添加System.Security.Principal.Windows程序包。
当然,这仅适用于Windows。
另一种选择是使用Claims:
ClaimsPrincipal.Current
为此,要添加的包是System.Security.Claims。在Windows中,默认情况下,标识为空。
关于.net - 在.NET Core控制台中获取当前用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36429549/