[英]How to get current logged in user of Domain of local system in mvc
我有一個組織的應用程序,用戶將使用域用戶登錄到他的系統,所以現在我想獲取該登錄用戶。 我嘗試了很多方法並在本地獲取用戶名,但我的應用程序在 IIS 上,它使用IIS APPPool\DefaultAppPool
獲取 IIS 用戶,而系統名稱和域卻沒有。
這是我用來獲取用戶名的代碼:
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,請分享。 提前致謝。
如果您有 Windows 身份驗證工作,那么當前用戶在HttpContext.User
中可用。
User.Identity.Name
將是用戶名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.