[英]How to get windows logged in user id from ASP.NET with anonymous access
我有一個在表單和匿名訪問上設置的Web應用程序。 我有一個默認頁面,我想在該頁面上獲取當前登錄的用戶,它是一個ASP.Net應用程序。
我怎樣才能做到這一點?
我相信您正在尋找HttpContext.User.Identity.Name
您好,您可以嘗試使用此代碼
WindowsIdentity wi = WindowsIdentity.GetCurrent();
var result = wi.Name;
var anonymous = wi.IsAnonymous; //For ensure your authentification mode
您可以使用此代碼
System.Web.HttpContext.Current.User.Identity.Name
但是您必須確保您已經在安全包(可能是httpmodule)的線程中添加了主體。 (如果您具有自定義身份驗證和授權)
此代碼有效:
var w = WindowsIdentity.GetCurrent().Name;
this.HttpContext.Trace.Warn(w);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.