2013-10-11 1 views
3

로컬 인트라넷에서 ASP.NET 양식을 제출하는 사용자의 전자 메일 주소를 가져 오려고합니다. 내 로컬 컴퓨터에서이를 테스트 할 때 정상적으로 작동합니다. 내가 게시 및 생산을 테스트를 시작할 때이 라인을 좋아하지 않는다 (74)System.DirectoryServices.DirectoryServicesCOMException : 작업 오류가 발생했습니다.

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 

An operations error occurred. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred. 


Source Error: 


Line 71:   adSearcher.SearchScope = SearchScope.Subtree; 
Line 72:   adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))"; 
Line 73:   SearchResult userObject = adSearcher.FindOne(); 
Line 74:   if (userObject != null) 
Line 75:   { 

Source File: c:\Web\Support-t\Content\Default.aspx.cs Line: 73 

Stack Trace: 


[DirectoryServicesCOMException (0x80072020): An operations error occurred. 
] 
    System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +628309 
    System.DirectoryServices.DirectoryEntry.Bind() +44 
    System.DirectoryServices.DirectoryEntry.get_AdsObject() +42 
    System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +98 
    System.DirectoryServices.DirectorySearcher.FindOne() +44 
    _Default.Page_Load(Object sender, EventArgs e) in c:\Web\Support-t\Content\Default.aspx.cs:73 
    System.Web.UI.Control.LoadRecursive() +71 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178 



-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033 

이 코드 블록은 단지 즉각적인 결과를 얻을 수있는, 그래서 테스트를 위해 페이지로드에 ....하지만, 로컬 컴퓨터에 VS에서 디버깅 할 때 그것은 결코

IIdentity id = WindowsIdentity.GetCurrent(); 
     WindowsIdentity winId = id as WindowsIdentity; 

     if (id == null) 
     { 
      txtDetailedProblem.Text = "Identity is not a windows identity"; 
      return; 
     } 

     string userInQuestion = winId.Name.Split('\\')[1]; 
     string myDomain = winId.Name.Split('\\')[0]; // this is the domain that the user is in 
     // the account that this program runs in should be authenticated in there      
     DirectoryEntry entry = new DirectoryEntry("LDAP://" + myDomain); 
     DirectorySearcher adSearcher = new DirectorySearcher(entry); 

     adSearcher.SearchScope = SearchScope.Subtree; 
     adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))"; 
     SearchResult userObject = adSearcher.FindOne(); 
     if (userObject != null) 
     { 
      string[] props = new string[] {"mail"}; 
      foreach (string prop in props) 
      { 
       txtTEST.Text = prop.ToString() + " " + userObject.Properties[prop][0].ToString(); 
      } 
     } 
+0

... 생산에서 페이지의 로딩에 도착 없지만 잘 작동 나는 당신의 생산 웹 서버에 신원이 어디가 AD에 액세스 할 수있는 권한이 가정 아니. 프로덕션 웹 서버의 apppool에 어떤 ID가 구성되어 있습니까? – rene

+0

중복 가능한 [System.DirectoryServices.DirectoryServicesCOMException : 작업 오류가 발생했습니다] (http://stackoverflow.com/questions/13688031/system-directoryservices-directoryservicescomexception-an-operations-error-occu) – rene

+0

사용자 정의로 설정 됨 – KBriz

답변

3
IIdentity id = WindowsIdentity.GetCurrent(); 
      WindowsIdentity winId = id as WindowsIdentity; 

      if (id == null) 
      { 
       CurrentUserEmail = "identity is not a windows identity"; 
       return; 
      } 

      var name = winId.Name; 

      string userInQuestion = name.Split('\\')[1]; 
      string myDomain = name.Split('\\')[0]; // this is the domain that the user is in 
      // the account that this program runs in should be authenticated in there      

      using (HostingEnvironment.Impersonate()) 
      { 
       DirectoryEntry entry = new DirectoryEntry("LDAP://" + myDomain); 
       DirectorySearcher adSearcher = new DirectorySearcher(entry); 

       adSearcher.SearchScope = SearchScope.Subtree; 
       adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))"; 
       SearchResult userObject = adSearcher.FindOne(); 
       if (userObject != null) 
       { 
        string[] props = new string[] {"mail"}; 
        foreach (string prop in props) 
        { //when it works set variable to CurrentUserEmail instead of txtDetailPrblem textbox 
         CurrentUserEmail = userObject.Properties[prop][0].ToString(); 
        } 
       } 

      } 
관련 문제