c# - .Net 的目录服务抛出一个奇怪的异常

标签 c# .net ldap directory service

我有一个用于检查用户凭据的小型 C# 解决方案。它适用于我的两个队友,但在我的 PC 上出现异常。

相关代码:

PrincipalContext context = new PrincipalContext(ContextType.Domain);
if (context.ValidateCredentials(System.Environment.UserDomainName + "\\" + usr, pwd))
     return true;
else
     return false;

异常(exception)情况是:

DirectoryOperationException, "The server cannot handle directory requests.".

我尝试使用明确的服务器名称和 636 端口号创建上下文,但这也没有帮助。

有什么想法吗?

最佳答案

我在使用 IIS Express 和 VS 2010 时也遇到了这个问题。为我解决这个问题的是对另一个线程的评论。

Validate a username and password against Active Directory?

但我会为您节省点击和搜索...:) 只需添加 ContextOpations.Negotiate 给您验证凭证调用,如下所示。

bool valid = context.ValidateCredentials(user, pass, ***ContextOptions.Negotiate***);

关于c# - .Net 的目录服务抛出一个奇怪的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3694919/

相关文章:

c# - 通过表达式树编译动态实例方法,具有私有(private)和 protected 访问权限?

c# - HttpWebRequest 和 gzip

svn - 设置 Apache 和 Subversion 以使用 LDAP (Windows Active Directory) 组身份验证

C# 遍历 DataGridView 并更改行颜色

c# - 当发出同步 I/O 调用时,当前线程 (C#) 的 ThreadState 是什么?

asp.net - 从 .aspx 页面直接到达 SessionId

c# - 扩展方法 : Performance issue when using too much?

Active Directory 根 DN 中的 php ldap_search - 空结果

java - Spring 的 SimpleNamingContextBuilder 和 LDAP

c# - 用于搜索嵌套级别的正则表达式