获取System.net.webexception的Active Directory调用

时间:2013-10-09 19:19:14

标签: asp.net active-directory system.net.webexception

我有一个asp .net程序,通过端点与Active Directory服务器通信。我正在进行三项操作。 GetAllActiveDirectoryUsers(),GetAllActiveDirectoryGroups(),SaveUserToGroupMapping()

在GetAllActiveDirectoryUsers()中,从AD中提取所有UserPrincipal对象并将该信息填充到Database表中。 正常工作

在GetAllActiveDirectoryGroups()中,从AD中提取所有GroupPrincipal对象并将该信息填充到数据库表正常工作

在SaveUserToGroupMapping()中获取所有userPrincipal对象,并为每个用户Principal,我找到一个UserPrincipal.GetGroups()。有近6500个用户主体对象并为每个userPrincipal对象执行组主体是一种耗时。拉出所有userprincipal和userPrincipal.GetGroup()需要大约65分钟。 突然中断

foreach(UserPrincipal userPrincipal in myADUserPrincipalResults)
{
  foreach(GroupPrincipal groupPrincipal in userPrincipal.GetGroups())
  {
    //Build my custom C# object with groupPrincipal
  }
}

我的Web应用程序部署在Web服务器框上,上面显示的userprincipal和group principal上的代码片段位于app server框中。它是调用Active Directory服务器的应用服务器。 Web应用程序只有一个单击按钮,可以执行顺序代码。

我尝试捕获此代码的异常。此代码适用于特定数量的用户,并突然抛出异常,如下所示:这是来自Web服务器的异常日志。我在应用服务器上看不到任何异常日志。

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---

我不确定问题出在哪里。是因为AD服务器或Web服务器或应用服务器。关键是我已经编写了其他日志以了解代码执行成功的程度,并且我看到代码片段中的循环工作正常一段时间,比如一小时,然后突然失败。

对此进行调试或分析问题的任何帮助都非常感谢?

0 个答案:

没有答案