我有一個組織的應用程式,其中用戶將使用域用戶登錄到他的系統,所以現在我想獲得該登錄用戶。我嘗試了很多方法并在本地獲取用戶名,但我的應用程式在 IIS 上,它獲取 IIS 用戶,IIS APPPool\DefaultAppPool而系統名稱和域獲取但用戶名沒有。
這是我用于獲取用戶名的代碼:
Request.ServerVariables.Get("logon_user");
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Environment.GetEnvironmentVariable("USERNAME");
System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
如果有人知道如何獲取本地用戶名而不是 IIS,請分享。提前致謝。
uj5u.com熱心網友回復:
如果您使用 Windows 身份驗證,則當前用戶在HttpContext.User.
User.Identity.Name 將是用戶名。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/399909.html
標籤:C# asp.net-mvc 验证 活动目录 窗口认证
