1
我需要根據Active Directory對用戶進行身份驗證。在Visual Studio以及LinqPad中運行相同的代碼。 LinqPad工作正常,但是在Visual Studio中,它有一個非常有益的未知的錯誤錯誤,堆棧跟蹤如下:Active Directory Linqpad vs 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之外運行了exe,不管是否使用Admin,也使用cmd行中的runas。 如果任何人有任何知識,爲什麼這些行爲不同,那麼將非常感激。