簡體   English   中英

活動目錄 c# 網站托管在 IIS

[英]active directory c# website hosted in IIS

我在一個帶有 Active Directory 的網絡上。 我編寫了一個 MVC c# web 應用程序來使用 header 中的網站顯示此人的姓名。 代碼是

 PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
 UserPrincipal user = UserPrincipal.Current;
 Debug.Writeline(user.DisplayName); //but when i host it in a local server (IIS) this keeps outputing my name

每當我使用別人的計算機訪問該網站時,我仍然會在 header 中獲得我的名字。

我該如何解決這個問題,所以每當我在別人的計算機上時,我都會在 header 中得到他們的名字?

UserPrincipal user = UserPrincipal.Current; 將向用戶顯示 web 應用程序正在運行。 當您從 ActiveDirectory(使用PrincipalContext )查找用戶帳戶時使用UserPrincipal

您應該使用HttpContext.Current.User.Identity.Name來查找正在訪問該站點的用戶,但請檢查以確保HttpContext.Current不是 null。

關於HttpContext class 的文檔

暫無
暫無

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

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