NET的目录服务抛出一个奇怪的异常抛出、异常、奇怪、目录

2023-09-03 04:49:48 作者:习惯自己回家

我用来检查用户凭据的小C#的解决方案。它工作正常的两个我的队友,但我的电脑上我得到一个异常。

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.

相关code:

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

和的例外是:

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

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

我试图创建上下文明确的服务器名和636端口号,但​​这并没有很好的帮助。

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

任何想法?

推荐答案

我有这个问题:事情正在处理我的dev的机器,但在服务器上没有工作。原来,IIS服务器上的成立,为LOCALMACHINE运行。我改成了网络服务(默认值),事情开始工作。

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.

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

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