2016-08-23 15 views
0

최근에 .Net 4에서 4.6.1로 업그레이드 한 MVC 인트라넷 앱이 있습니다. 이 응용 프로그램은 Controller의 User.Identity 속성에서 사용할 수없는 세부 정보를로드하고 최근까지 완벽하게 처리 할 때까지 Active Directory에서 사용자 세부 정보를 쿼리합니다. 0x80005000 (비주얼 스튜디오 2015에서 디버깅 할 때UserPrincipal.FindByIdentity COM 오류가 발생합니다. 0x80005000

public static void foo() 
{ 
    var usr = LookupUser("MyDomain", "jbloggs"); 
    ... 
} 

private static UserPrincipal LookupUser(string domain, string username) 
{ 
    Console.WriteLine($"Lookup {domain}\\{username}"); 
    using (var ctx = new PrincipalContext(ContextType.Domain, domain)) 
    { 
     using (var user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, username)) 
     { 
      if (user == null) 
      { 
       Console.WriteLine("User not found"); 
       return; 
      } 

      Console.WriteLine($"Found {domain}\\{username}"); 
      Console.WriteLine($"DisplayName = {user.DisplayName}"); 
      Console.WriteLine($"Office = {user.GetString("physicalDeliveryOfficeName")}"); 
      Console.WriteLine(""); 

      return user; 
     } 
    } 
} 

코드는 잘 실행하지만 (윈도우 서버 2008 R2에 V6.1의 SP1)을 IIS 상자에서 실행중인 경우, COMException 예외 : 코드는 다음과 같이 보입니다 UserPrincipal.FindByIdentity를 호출 할 때 다음과 같이)()

웹 응용 프로그램은 전용 응용 프로그램 풀에서 실행되는

, 설정이있는 다음과 같습니다

  • 닷넷 프레임 워크 버전 = 4.0
  • 신원 = MyDomain \ MyAppServiceUser (비 대화 형 AD 사용자 계정)

다른 모든 설정은 기본값에 따라 있습니다 거짓

  • 로드 사용자 프로필 =. 익명 및 Windows 인증을 모두 사용하여 응용 프로그램 자체가 실행 중입니다. 서버에 .Net 4.6.1이 설치되어 있고 인트라넷 응용 프로그램의 다른 모든 요소가 제대로 실행되고있는 것 같습니다.

    이 문제를봤을 때 대부분의 대답은 AD를 쿼리하는 서비스 계정의 권한에 문제가 있음을 나타냅니다. 응용 프로그램 풀이 DOES로 실행되는 서비스 계정이 Active Directory를 쿼리 할 수있는 권한이 있는지 확인하기 위해 위의 코드를 콘솔 응용 프로그램에서 사용하고 서버와 서비스 계정 모두로 실행했습니다. 인스턴스는 잘 작동합니다. IIS에서 실행될 때만 폭탄이 터집니다.

    PrincipalContext (OU 컨테이너 경로 등 포함)를 만드는 수많은 변형을 시도했지만 결과는 항상 동일합니다.

    나는이 일에 열심히 노력하고 있으므로 도움을 주시면 대단히 감사하겠습니다.

    업데이트 - 자세한 내용

    • 예외 유형 : 함께 System.Runtime.InteropServices.COMException
    • 예외 메시지 : 알 수없는 오류 (0x80005000)
    • 스택 추적 :

    at System.DirectoryServices.DirectoryEntry.Bind (Boolean throwIfFail) System.DirectoryServices.PropertyValueCollection..ctor에서 System.DirectoryServices.PropertyValueCollection.PopulateList()에서 System.DirectoryServices.DirectoryEntry.get_AdsObject()에서 System.DirectoryServices.DirectoryEntry.Bind() (하여 DirectoryEntry 항목, 문자열 propertyName 형식에서) System.DirectoryServices.AccountManagement에서 System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() 에서 System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() 에서 System.DirectoryServices.PropertyCollection.get_Item (문자열 propertyName 형식)에서 .PrincipalContext. System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper에서 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() (PrincipalContext 상황, 유형 principalType, Nullable`1 identityType, 문자열 identityValue, 날짜 시간 refDate)에서에서) ( 를 초기화 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType (PrincipalContext 컨텍스트 유형 principalType, identityType identityType, 문자열 identityValue) System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity에서 (PrincipalContext 상황, identityType identityType, 문자열 identityValue) AP = 연합 뉴스에서 ollo.Security.ActiveDirectoryUser.Find (String identityName)

  • +0

    이 방법이 효과가 있습니까? : http://stackoverflow.com/a/1722429/3709746 –

    +0

    불행히도 - DirectorySearcher.FindOne() - 다음 주석에서 코드를 호출 할 때 같은 오류가 발생합니다. – Pete

    +0

    var de = new DirectoryEntry ("LDAP : // MyDC.MyDomain.com/DC=MyDomain,DC=com ","MyDomain \\ ServiceUser ","password "); \t var ds = new DirectorySearcher (de); \t ds.Filter = $ "(& (objectClass = user) (objectCategory = user) (sAMAccountName = {userName})))"; \t ds.PropertiesToLoad.Add ("physicalDeliveryOfficeName"); \t var result = ds.FindOne(); // 여기에 불어서 – Pete

    답변

    0

    head-scratcher에 대해 이야기하십시오. 나는 서클을 돌아 다니면서 하루의 가장 좋은 시간을 보냈습니다.

    모든 도움을 주신 Rahul에게 감사드립니다. 결국, 그의 제안에 따라 네트워크 서비스로 실행되는 새로운 앱 풀을 만들었고 광고 조회가 그 아래에서 완벽하게 작동했습니다. 안타깝게도 내 앱이 네트워크 리소스에 액세스하기 때문에 AD 사용자로 실행해야하므로 AD 서비스 계정에 대한 자격 증명을 이전에 사용했던 계정으로 변경했습니다. 계속 작업 중입니다.

    ?!?

    왜 이런 경우가 될지 모르겠다. 두 앱 풀은 정확히 동일한 설정을 가지고 있지만 조회를 수행 할 수 있고 다른 하나는 할 수 없다. 필자는 테스트 및 프로덕션 인스턴스를 새 응용 프로그램 풀로 전환하고 이전 인스턴스를 삭제했으며 모든 것이 훌륭하게 똑딱 거리고 있습니다.

    +0

    그래도 문제가 해결되었을 수 있습니다. 너처럼) 나는 왜 그런지 모르겠다. 같은 오류가 발생하지만 더 일정합니다. 다른 사용자에게 도움이되는 경우 0x80005000 오류 코드는 잘못된 ADSI 경로 이름을 나타냅니다. 이 경로는 PrincipalContext 초기화 중에 검색되며 RootDSE의 wellKnownObjects 특성에서 가져옵니다. 필자의 경우에는 OU에 슬래시 "/"가 포함되어 LDAP 경로를 방해했습니다. Microsoft는 여기에 ADSI 오류 코드의 일부 목록을 제공합니다. https://msdn.microsoft.com/en-us/library/aa705940(v=vs.85).aspx – ARP

    0

    우리에게 이것은 McAfee HIPS 서비스가 TCP 포트 135를 통한 아웃 바운드/인바운드 WMI 연결을 차단했기 때문입니다.