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

发布于 2024-09-18 23:52:57 字数 459 浏览 2 评论 0原文

我有一个小型 C# 解决方案,用于检查用户凭据。对于我的两个队友来说,它工作得很好,但在我的电脑上,我遇到了一个例外。

相关代码:

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

例外情况是:

DirectoryOperationException,“服务器无法处理目录请求。”。

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

有什么想法吗?

I have a small C# solution used to check users credentials. It works fine for two of my teammates, but on my PC I get an exception.

The relevant code:

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

And the exception is:

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

I tried creating context with the explicit server name and the 636 port number, but this didn't help as well.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷鸟归林 2024-09-25 23:52:57

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

根据 Active Directory 验证用户名和密码?

但我会为您节省点击和搜索...:) 只需将 ContextOpations.Negotiate 添加到您的 Validate Credentials 调用中,如下所示。

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

I had this problem too using IIS Express and VS 2010. What fixed it for me was a comment on another thread.

Validate a username and password against Active Directory?

but i'll save you the click and search... :) Just add ContextOpations.Negotiate to you Validate Credentials call like below.

bool valid = context.ValidateCredentials(user, pass, ***ContextOptions.Negotiate***);
失眠症患者 2024-09-25 23:52:57

我遇到了这个问题:在我的开发机器上一切正常,但在服务器上却不起作用。结果发现服务器上的 IIS 已设置为作为 LocalMachine 运行。我将其更改为 NetworkService (默认),一切开始工作。

因此,基本上检查应用程序池的用户是否在 IIS 上运行。

I had this issue: things were working on my dev machine but didn't work on the server. Turned out that IIS on the server was set up to run as LocalMachine. I changed it to NetworkService (the default) and things started working.

So basically check the user of the app pool if this is running on IIS.

阳光下慵懒的猫 2024-09-25 23:52:57

我必须创建一个新的应用程序池并将其分配给 .NET 2.0,然后将新的应用程序池分配给我们的 Web 应用程序,然后它就开始工作了。我们有 .NET 3.5 SP2,因此该修补程序对我们来说并不理想。由于WWW服务通常是本地系统,我也对此提出质疑。但由于它与 .NET 和安全相关,所以我首先尝试了应用程序池,它成功了。

I had to just create a new app pool and assign it .NET 2.0, then assign the new app pool to our web app, and it started working. We had .NET 3.5 SP2, so the hotfix wasn't ideal for us. Since the WWW service is usually Local System, I questioned that too. But since it was .NET and security related, I gave a shot at the app pool first and it worked.

无力看清 2024-09-25 23:52:57

也许您需要修补程序?

并且您是管理员,或者您的服务运行时使用的 ID 是你的电脑上有管理员吗?

我想您已经研究过这个:

"您可能会收到一个不太有用的 DirectoryOperationException(“服务器无法处理目录请求。”) 这有什么不那么有趣的问题是它甚至没有尝试与服务器通信。解决方案是将端口号添加到服务器,因此我没有传递“Server”来打开 LdapConnection,而是传递了“server:636”。 LDAPS 是端口 636,而不是 LDAP 使用的 389 端口。”


好点,我不认为 Win7/.NET 3.5 需要该补丁。这个问题中提供的信息怎么样:

Perhaps you need the hotfix?

And you are an Admin or the id that your service is running under is an Admin on your PC right?

I take it you already looked into this:

"You may receive a less than helpful DirectoryOperationException(“The server cannot handle directory requests.”) what isn’t quite so amusing about this is that it didn’t even try to communicate with the server. The solution was to add the port number to the server. So instead of passing “Server” to open the LdapConnection, I passed “server:636”. By the way, LDAPS is port 636 – rather than the 389 port used by LDAP."


Good point, I wouldn't expect that Win7/.NET 3.5 would need that patch. How about the info provided in this question:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文