Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

UserPrincipal.GetGroups throws System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException

$
0
0

I wrote a web application which uses Active Directory user info for identiry authentication and Groups info for role access control. but I found it is instable. 

I used the code as follow.

try
{
   UserPrincipal usr = GetUserPrincipal(samAccountName); // a function get a UserPrincepal instance from Active Directory

   if(usr != null)
   {
      PrincipalSearchResult<Principal> oPrincipalSearchResult = usr.GetGroups();

      foreach (Principal oResult in oPrincipalSearchResult)
      {
          //......
      }

   }
}
catch (Exception e)
{
   
}

When user logs in , it shows the appropriate menu, but some times it shows a empty menu, and it is fine in a little time.

I debbug it and findd when it step into 

PrincipalSearchResult<Principal> oPrincipalSearchResult = usr.GetGroups();

it throws a System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException.

The Active Directory Server runs  Microsoft Windows Server 2008 R2 (64bit)


Viewing all articles
Browse latest Browse all 8156

Trending Articles