【发布时间】:2016-01-06 15:23:48
【问题描述】:
我需要针对 Active Directory 对用户进行身份验证。相同的代码在 Visual Studio 和 LinqPad 中运行。 LinqPad 工作正常但是在 Visual Studio 中,它会出现一个非常有用的未知错误,堆栈跟踪如下:
System.DirectoryServices.Protocols.LdapException: A local error occurred.
at System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential newCredential, Boolean needSetCredential)
at System.DirectoryServices.AccountManagement.CredentialValidator.lockedLdapBind(LdapConnection current, NetworkCredential creds, ContextOptions contextOptions)
at System.DirectoryServices.AccountManagement.CredentialValidator.BindLdap(NetworkCredential creds, ContextOptions contextOptions)
at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)
两者中但仅在 LinqPad 中运行的代码是:
using (System.DirectoryServices.AccountManagement.PrincipalContext pc = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain))
{
return pc.ValidateCredentials("SomeName", SomePassword");
}
我还在 VS 之外使用 / 不使用 Admin 运行了 exe,并且还使用了 cmd 行中的 runas。 如果有人知道为什么这些行为不同,那将不胜感激。
【问题讨论】:
标签: c# visual-studio active-directory linqpad