[英]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.