2017-10-10 11 views
0

以下は、VB.NETコードでLDAPに接続しようとするコードです。以下のコードはVS 2015のローカルPCで動作しますが、サーバーに同じコードをホストするとエラーが発生します。サーバーIISでLDAP接続が機能していませんが、ローカルVS 2015で動作しています

FindAll()関数を呼び出す方法に問題がありますか?この同じ関数は私のローカルPCに私に必要な値を返しますが、サーバで例外を与えます。私は、サーバーからの例外を捕獲し、コード

Private entry As DirectoryEntry = Nothing 

Public Enum ADProperties 
    distinguishedName 
    displayName 
    telephoneNumber 
    samAccountName 
    manager 
    title 
    department 
    givenName 
    sn 
End Enum 

entry = New DirectoryEntry("LDAP://DC=asia,DC=contoso,DC=com") 

Dim lstSearch As List(Of LDAPSearchResult) = New List(Of LDAPSearchResult) 

lstSearch = Search(ADProperties.samAccountName, parts(1).ToString()) 

       If Not lstSearch Is Nothing AndAlso lstSearch.Count > 0 Then 
        For Each a As LDAPSearchResult In lstSearch 
         email = a.UserPrincipalName 
         userid = a.ComputerUserId 
         name = a.GivenName 
         Exit For 
        Next 

Public Function Search([property] As ADProperties, propertyValue As [String]) As List(Of LDAPSearchResult) 
    Dim lstSearchResults As New List(Of LDAPSearchResult)() 

    Try 
     Dim search__1 As New DirectorySearcher(entry) 
     Dim resultCollection As SearchResultCollection 


     LoadProperties(search__1) 

     search__1.Filter = String.Concat("(", [property].ToString(), "=", propertyValue, ")") 

     resultCollection = search__1.FindAll() //Exception is caught here 

     If resultCollection IsNot Nothing Then 
      For Each result As SearchResult In resultCollection 
       Dim objSearchResult As New LDAPSearchResult() 

       MapToObject(result, objSearchResult) 

       lstSearchResults.Add(objSearchResult) 
      Next 
     End If 

    Catch ex As Exception 
     Throw New Exception(ex.Message.ToString()) 
    End Try 

    Return lstSearchResults 
End Function 

Private Sub MapToObject(result As SearchResult, ByRef objSearchResult As LDAPSearchResult) 
    Try 

     If result.Properties("title").Count > 0 Then 
      objSearchResult.Title = result.Properties("title")(0).ToString() 
     End If 
     If result.Properties("distinguishedName").Count > 0 Then 
      objSearchResult.distinguishedName = result.Properties("distinguishedName")(0).ToString() 
     End If 
     If result.Properties("displayName").Count > 0 Then 
      objSearchResult.displayName = result.Properties("displayname")(0).ToString() 
     End If 
     If result.Properties("telephoneNumber").Count > 0 Then 
      objSearchResult.telephoneNumber = result.Properties("telephoneNumber")(0).ToString() 
     End If 
     If result.Properties("samAccountName").Count > 0 Then 
      objSearchResult.samAccountName = result.Properties("samAccountName")(0).ToString() 
     End If 

     If result.Properties("department").Count > 0 Then 
      objSearchResult.department = result.Properties("department")(0).ToString() 
     End If 
     If result.Properties("givenName").Count > 0 Then 
      objSearchResult.FirstName = result.Properties("givenName")(0).ToString() 
     End If 
     If result.Properties("sn").Count > 0 Then 
      objSearchResult.LastName = result.Properties("sn")(0).ToString() 
     End If 
    Catch ex As Exception 
     ex.Message.ToString() 
    End Try 
End Sub 

エラーが

System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 
System.DirectoryServices.DirectoryEntry.Bind() 
System.DirectoryServices.DirectoryEntry.get_AdsObject() 
System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) 

以下で以下のコードを追加することで解決

+0

完全な例外を表示します。 –

+0

以下はSystem.DirectoryServices.DirectorySearcherでSystem.DirectoryServices.DirectoryEntry.get_AdsObject() でSystem.DirectoryServices.DirectoryEntry.Bind() でSystem.DirectoryServices.DirectoryEntry.Bind(ブールthrowIfFail) で完全な例外 です。 FindAll(Boolean findMoreThanOne) .Search(ADPropertiesプロパティ、String propertyValue)] – ssuhas76

+0

例外のメッセージ本文がありません。あなたのコードに最初の行を追加してください - あなたが表示しているのは、例外メッセージなしの例外スタックトレースです! –

答えて

0

問題を助けてくださいと言う後に以下のエラーメッセージを貼り付けていますweb.config

<identity impersonate="false"> 
関連する問題