简体   繁体   English

.Net的目录服务引发了一个奇怪的例外

[英].Net's Directory Services throws a strange exception

I have a small C# solution used to check users credentials. 我有一个用于检查用户凭据的小型C#解决方案。 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.". DirectoryOperationException,“服务器无法处理目录请求。”。

I tried creating context with the explicit server name and the 636 port number, but this didn't help as well. 我尝试使用显式服务器名称和636端口号创建上下文,但这也没有帮助。

Any ideas? 有任何想法吗?

I had this problem too using IIS Express and VS 2010. What fixed it for me was a comment on another thread. 我也使用IIS Express和VS 2010解决了这个问题。为我修复的是对另一个线程的评论。

Validate a username and password against Active Directory? 验证Active Directory的用户名和密码?

but i'll save you the click and search... :) Just add ContextOpations.Negotiate to you Validate Credentials call like below. 但我会保存你的点击和搜索... :)只需将ContextOpations.Negotiate添加到你验证如下所示的凭据调用。

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

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. 原来,服务器上的IIS设置为以LocalMachine身份运行。 I changed it to NetworkService (the default) and things started working. 我把它改为NetworkService(默认),事情就开始了。

So basically check the user of the app pool if this is running on IIS. 所以基本上检查应用程序池的用户是否在IIS上运行。

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. 我不得不创建一个新的应用程序池并将其分配给.NET 2.0,然后将新的应用程序池分配给我们的Web应用程序,它开始工作。 We had .NET 3.5 SP2, so the hotfix wasn't ideal for us. 我们有.NET 3.5 SP2,所以这个修补程序对我们来说并不理想。 Since the WWW service is usually Local System, I questioned that too. 由于WWW服务通常是Local System,我也对此提出质疑。 But since it was .NET and security related, I gave a shot at the app pool first and it worked. 但由于它与.NET和安全相关,我先在应用程序池中进行了一次尝试,然后才有效。

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? 您是管理员或运行您的服务的ID是PC上的管理员吗?

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." “你可能会收到一个不太有用的DirectoryOperationException(”服务器无法处理目录请求。“)对此不太有趣的是它甚至没有尝试与服务器通信。解决方案是添加端口因此,我没有通过“Server”来打开LdapConnection,而是通过“server:636”。顺便说一下,LDAPS是端口636 - 而不是LDAP使用的389端口。“


Good point, I wouldn't expect that Win7/.NET 3.5 would need that patch. 好的,我不希望Win7 / .NET 3.5需要那个补丁。 How about the info provided in this question: 如何在这个问题中提供的信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM