[英]UserPrincipal Security. Disabling unwanted smart card prompt?
我有一個帶有登錄屏幕的應用程序,供用戶根據域對自己進行身份驗證。 為此,我使用了 System.DirectoryServices.AccountManagement PrincipalContext/UserPrincipal 類。
PrincipalContext domain = new PrincipalContext(ContextType.Domain, "mydomain");
if (domain.ValidateCredentials(UserName, Password))
{
//do stuff
}
這在絕大多數情況下都非常有效。 但是,對於少數 select 人來說,這個“domain.ValidateCredentials”方法會在發現用戶名在域中有效時,會自動提示插入智能卡。 只需再次關閉提示將允許我的應用程序繼續,但我寧願完全擺脫它。
我沒有太多運氣找到原因/解決方案。 任何援助將不勝感激!
我今天也遇到了同樣的問題。 對我有用的解決方案:將[System.DirectoryServices.AccountManagement.ContextOptions]'Negotiate'
添加到ValidateCredentials
方法中:
domain.ValidateCredentials(UserName, Password, [System.DirectoryServices.AccountManagement.ContextOptions]'Negotiate')
將 ContextOptions.Negotiate 添加到對 ValidateCredentials 的調用確實可以解決問題,因為這會強制使用帶有用戶名和密碼的 Kerberos 或 NTLM,繞過詢問智能卡: https://docs.microsoft.com/en-us/dotnet/api/ system.directoryservices.accountmanagement.contextoptions?view=dotnet-plat-ext-6.0 。
由於 using 語句可能已經在引用 AccountManagement 的代碼中,因此簡單地使用枚舉會更加簡潔:
domain.ValidateCredentials(UserName, Password, ContextOptions.Negotiate)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.