![](/img/trans.png)
[英]Is it possible to get the Windows logon name with site running asp.net forms authentication?
[英]Get windows logon user in asp.net web forms iis
我想以asp.net Web形式獲取活動目錄登錄用戶。我使用了以下代碼段,但在運行時或iis上均不起作用。
Request.ServerVariables["REMOTE_USER"].ToString();
嘗試使用System.Web.HttpContext.Current.User.Identity;
獲取經過身份驗證的用戶的詳細信息。
使用目錄條目獲取用戶狀態。
string username = "";
string userpassword = "";
bool valid = false;
using (DirectoryEntry Direntry = new DirectoryEntry(path, username, userpassword))
{
using (DirectorySearcher Dsearch = new DirectorySearcher(Direntry))
{
Dsearch.Filter = "(cn=" + username + ")";
try
{
SearchResult adsSearchResult = Dsearch.FindOne();
if (adsSearchResult != null)
{
valid = true;
}
}
catch (Exception ex)
{
}
finally
{
Direntry.Close();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.