I have an asp .net program that talks to Active Directory server through an end point. I am performing three operation. GetAllActiveDirectoryUsers(), GetAllActiveDirectoryGroups(), SaveUserToGroupMapping()
In GetAllActiveDirectoryUsers() am pulling all UserPrincipal objects from AD and populating that information to a Database table. Works fine
In GetAllActiveDirectoryGroups() am pulling all GroupPrincipal objects from AD and populating that information to a Database table Works fine
In SaveUserToGroupMapping() am getting all userPrincipal Objects and for each user Principal, I am finding a UserPrincipal.GetGroups(). There are almost 6500 user principal objects and performing a group principal for each userPrincipal Objects is kind of time consuming. It takes around 65 minutes to pull all userprincipal and userPrincipal.GetGroup(). Breaks abruptly
foreach(UserPrincipal userPrincipal in myADUserPrincipalResults) { foreach(GroupPrincipal groupPrincipal in userPrincipal.GetGroups()) { //Build my custom C# object with groupPrincipal } }
My web application is deployed on web server box and the code snippet shown above on the userprincipal and group principal is in the app server box. Its the app server that makes calls to Active Directory server. The web application just has a button to click and it kicks of the sequential code execution.
I have try catch exceptions around this code. This code works fine for certain number of users and suddenly it throws an exception as shown below: This is the exception log from the web server. I don't see any exception logs on the app server.
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 ---
I am not sure where the problem is. Is it because of the AD server or web server or app server. The point is I have other logs written to know to what extent the code execution was successfull and I see that the loop in the code snippet works fine for some time say one hour and after that its suddenly failing.
Any help in debugging this or analysing on what the problem would be is much appreciated?