簡體   English   中英

在IIS Web應用程序中,如何獲取Windows用戶名? -不是進程用戶名

[英]in an IIS web app, how do I get the windows user name? - not the process username

我繼承了一個舊的asp.net網絡應用程序。 登錄過程的一部分旨在收集Windows用戶名(而不是過程用戶名)。 這曾經工作(幾年前),但是系統的新編譯返回了“應用程序池”名稱/用戶名,而不是Windows用戶名。

用戶名是在網站進行身份驗證之前收集的,最初是使用HttpContext.Current.User.Identity.Name,我嘗試了所有建議的其他選項,但結果沒有變化。

string loginName;
loginName = Environment.UserName;
loginName = System.Windows.Forms.SystemInformation.UserName;
loginName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
loginName = HttpContext.Current.User.Identity.Name;
loginName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
loginName = System.Windows.Forms.SystemInformation.UserName;
loginName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.SamAccountName;
loginName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName;

我一次嘗試了一次(並非全部嘗試一次),並且在目標環境中只獲得了應用程序池名稱或應用程序池用戶名。 我已經嘗試了IIS中身份驗證的每種組合,唯一起作用的是ASP.NET模擬,它從應用程序池名稱更改為模擬用戶名。

在從Visual Studio啟動的本地PC上,它們都可以返回登錄的Windows用戶名。

我對asp.net網絡應用程序還很陌生,而且我不知道還能嘗試什么。

您偶然發現了答案。 如果希望服務器自動認識Windows用戶,則需要將該Windows用戶的憑據傳遞給應用程序。 如果使用Kerberos或NTML身份驗證選項(Windows身份驗證),則會自動傳遞一組憑據。 否則,您需要提示用戶輸入憑據。 您不必使用模擬,但是如果您的應用程序池用戶具有對dc目錄的足夠訪問權限,則可以以編程方式模擬已登錄的用戶。 有關更多信息,請訪問: https : //docs.microsoft.com/zh-cn/previous-versions/msp-np/ff647405(v=pandp.10)#impersonating-the-original-caller-programmatically

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM