2011-11-17 144 views
1

我無法使用LDAP爲ASP.NET Web應用程序成功驗證用戶。我在我們自己的網絡上針對Active Directory完成了這項工作,但這是針對我們網絡外部的OID(Oracle Internet Directory)的服務器。驗證用戶使用LDAP登錄

通常,我使用下面的代碼沒有問題。

Dim myDirectoryEntry As New System.DirectoryServices.DirectoryEntry("LDAP://1.2.3.4:999/OU=SomeOU,DC=Something,DC=com") 
myDirectoryEntry.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Sealing 
myDirectoryEntry.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure 

Try 
    myDirectoryEntry.Username = txtUserID.Text.Trim 
    myDirectoryEntry.Password = txtPassword.Text.Trim 

    Dim mySearcher As New System.DirectoryServices.DirectorySearcher(myDirectoryEntry) 

    mySearcher.Filter = ("(anr= " & txtUserID.Text & ")") 

    Dim result As System.DirectoryServices.SearchResult = mySearcher.FindOne 
Catch ex As Exception 
    'failed log in handling 
End Try 

對於這種應用,我會針對目錄我們的網絡之外,上面的方法失敗(所請求的認證方法不被服務器支持)。

我可以用成功綁定到LDAP服務器:

Dim serverName As String = "1.2.3.4:999" 

Dim dn As String = "cn=somename,cn=users,dc=something,dc=gov" 

Dim ServerCon As New LdapConnection(serverName) 

ServerCon.AuthType = AuthType.Basic 

Dim cred As New System.Net.NetworkCredential(dn, "password") 

ServerCon.Bind(cred) 

在那之後,我一直沒能找到一種方法來驗證用戶的登錄信息與密碼,然後拉回來一些信息。

+1

請問我的答案[這個其他問題在這裏](http://stackoverflow.com/questions/290548/c-sharp-validate-a-username-and-password-against-active-directory/499716#499716 )幫助你? –

+0

@marc_s:謝謝,但沒有幫助(爲此,但對其他項目非常有用)。該應用程序正在違反OID,而不是Active Directory。我將編輯問題以包含此內容。 – monkeypushbutton

回答

0

可能是服務器不支持Kerberos身份驗證。當所請求的身份驗證方法不受支持時,目錄服務器必須返回您在響應中收到的錯誤代碼,並且無法設置連接的身份驗證狀態。這可能發生在SASL機制不受支持的情況下;支持SASL機制應列在root DSE中。