[英]Access to different domain in active directory using C# .net application works in local machine but not when hosted in IIS server
[英]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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.