My application is a website build in Asp.net 2.0 framework.I have used Windows authentication.
When the user log in I am trying to take all the groups in which the user is a "member of".
I am using System.DirectoryServices.AccountManagement dll for achievin g the same.
One user(only one)is not able to access the application.For all other usrs its working fine..when the user tries to access the appln getting an UNknown error and ASP.ner default error page gets displayed.
Exception of type:System.Interopservices.COMException
Also the errorcode of the COM exceptionI receive is:
ErrorCode:20497
Symbol: S_ADS_ERRORSOCCURRED
Description :One or more errors occurred
Source:System.Directoryservices...
While hosting in my system's IIS its working fine(hardcoded the username)...when the same code is deployed in development/production server ...the xception occurs.....
I am using the following code to retrieve the groups of the user from AD:
public
static List<User> GetActiveDirGroups(string domainId)
PrincipalContext objPC = new PrincipalContext(ContextType.Domain);
UserPrincipal objUserPrincipal = UserPrincipal.FindByIdentity(objPC, domainId);
List<User> groupUsers = new List<User>();
lock (objUserPrincipal)
PrincipalSearchResult<Principal> memGroups = objUserPrincipal.GetGroups();
if (!memGroups.Equals(null))
{
groupUsers = GetActivedirectory(memGroups, groupUsers, objPC);
}
The user is having 267 groups...then I am trying to iterate through this collection using code...
public static List<User> GetActivedirectory(PrincipalSearchResult<Principal> groups, List<User> groupUsers, PrincipalContext objPC)
IDisposable disposable;
int i = 0;
IEnumerator<Principal> iPrincipal = groups.GetEnumerator(); try
{
while (iPrincipal.MoveNext())
Principal objPrinciple = iPrincipal.Current; User grpUser = new User();
groupUsers.Add(grpUser);
}
}
catch (Exception ex)
{
throw ex;
}
return groupUsers;
}
Also Please note :
When I try to debug through the code hardcoding the user name I am able to login,but when I deployed the same code in development server it is throwing this exception.
Please help me to resolve the same.