![](/img/trans.png)
[英]Prevents auto (windows) authentication when browing intranet bound to Active Directory
[英]When is Active Directory Auto Detected
我正在構建一個將通過Active Directory驗證用戶身份的應用程序。 不需要驗證,也不需要添加或編輯用戶,僅需驗證憑據即可。 我發現了很多關於此的帖子-一些使用System.DirectoryServices.AccountManagement(.NET 3.5及更高版本)或使用LDAP DirectoryEntry ...
我想弄清楚是否必須指定AD服務器URL? 測試時,我不需要指定任何內容嗎?
何時自動檢測到AD服務器? 什么時候需要指定URL?
我可以打電話獲取自動檢測到的AD服務器URL嗎?
當您創建域PrincipalContext
或DirectoryContext
而不指定域或路徑時,將使用當前上下文。 即代碼正在執行的帳戶。 如果代碼在不在域中的帳戶下執行,則將引發異常。 這適用於在Windows窗體應用程序或服務中運行的天氣。
要針對某個域驗證憑據,您需要做的是:
public bool ValidateCredentials(string username, string password)
{
using (var principalcontext = new PrincipalContext(ContextType.Domain))
{
return principalContext.ValidateCredentials(username, password);
}
}
但是,由於許多原因,這不是最好的方法。 例如,即使用戶由於密碼過期等原因而無法登錄, ValidateCredentials
也可以返回true。其次,有一種更簡便的方法可將Active Directory單點登錄用於桌面應用程序:
var currentUser = UserPrincipal.Current;
這將返回當前用戶的主體,無需重新驗證,Windows已經進行了驗證,因此您已經知道該用戶有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.