2013-08-21 1 views
0

오류 1 : 작업 오류가 발생했습니다.UserPrincipal Getauthorizationgroups의 오류

오류 2 : 권한 그룹을 검색하는 동안 오류 (110)이 발생했습니다.

public static bool CheckGroupMembership(string userID, string groupName, string domain) 
{ 
    bool isMember = false; 

    // Get an error here, so then I use my username/password and it works... 
    PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain, domain); 

    UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(ADDomain, userID); 

    PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetAuthorizationGroups(); //<-- Error is here: 

    foreach (Principal oResult in oPrincipalSearchResult) 
    { 
     if (oResult.Name.ToLower().Trim() == groupName.ToLower().Trim()) 
     { 
      isMember = true; 
     } 
    } 
    return isMember; 
} 

내가 원격 서버에서 웹 페이지를 당겨하고 때 동일한 컴퓨터에서 디버깅하고 모든 작품, 그것은 단지 실패이.

답변

0

내가 한 일은 다음과 같습니다. 내가 seporated 및 SharePoint에서 독립을 유지하기 위해 DLL을 원하기 때문에

, 나는 내가이 추가 호출하는 DLL 파일에서 ...이 필요한 메소드는 SharePoint 호출에

 SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 
      .... method goes here .... 
     }); 

을이 추가 :

private static bool UserHasPermisions(string userAccount, List<string> list) 
    { 
     bool userHasPermisions = true; 

     if (list != null && list.Count > 0) 
     { 
      userHasPermisions = false; 

      foreach (string item in list) 
      { 
       if (CheckGroupMembership(userAccount, item, "domain.local goes here...")) 
       { 
        userHasPermisions = true; 
       } 
      } 
     } 

     return userHasPermisions; 
    } 


public static bool CheckGroupMembership(string userID, string groupName, string domain) 
    { 
     bool isMember = false; 

     try 
     { 
      PrincipalContext ADDomain = GetPrincipalContext(); 

      UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(ADDomain, userID); 

      PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetAuthorizationGroups(); 

      foreach (Principal oResult in oPrincipalSearchResult) 
      { 
       if (oResult.Name.ToLower().Trim() == groupName.ToLower().Trim()) 
       { 
        isMember = true; 
       } 
      } 
     } 
     catch { } 

     return isMember; 
    } 

    private static PrincipalContext GetPrincipalContext() 
    { 
     string domain = "your local domain"; 
     string defaultOU = "DC=domain here,DC=local"; 
     string serviceUser = @"domain here\read only system account"; 
     string servicePassword = @"password goes here"; 

     PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, domain, defaultOU, ContextOptions.SimpleBind, serviceUser, servicePassword); 

     return oPrincipalContext; 
    } 

나는이 경로를 가고 싶지 않았지만, DLL을 독립적으로 유지하기 위해서는해야했다.

관련 문제