Frage

Ich bin eine Verbindung zu einem Microsoft Active Directory-Server in einer DMZ von meiner .net-Anwendung (asp.net VB .net 4.0). Ich brauche eine neue „inetorgperson“ in einem OrgUnit namens „SingleCustomerAccount“ zu erstellen.

Ich habe den System.DirectoryServices.Protocols Namespace für die ganze Arbeit zu verwenden, da die ADSI-Klassen (System.DirectoryServices-Namespace) nicht funktionieren würde über die DMZ richtig.

Auf jeden Fall ist es gut gearbeitet, um Active Directory auf Windows Server 2003 R2 zu verbinden; jedoch sind wir Tests gegen Active Directory auf Windows Server 2008 R2 (2008r2 im nativen Modus für Wald und Domäne) in fahrbereitem Zustand zu aktualisieren.

Mein vorhandener Code einen Benutzer nicht funktioniert zu erstellen.

System.DirectoryServices.Protocols.DirectoryOperationException: The server cannot handle directory requests.
   at System.DirectoryServices.Protocols.LdapConnection.ConstructResponse(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
   at Salford.LDAP.LDAPUser.SaveNewToDirectory(String UsersFirstPassword) in C:\Projects\SCA\App_Code\SCA\LDAPUser.vb:line 1059
   at SCA.Web.Service.CitizenService.CreateNewAccount(String Username, String Title, String FirstName, String Surname, String Street, String City, String County, String Postcode, String EmailAddress, String HomeTel, String MobileTel, String UPRN, String SpinID, Int16 AccountLevel) in C:\Projects\SCA\App_Code\CitizenService.vb:line 255

Ich habe festgestellt, dass, wenn ich das Stück Code zu entfernen, die das Passwort Attribut hinzufügt, wird der Benutzer erstellt, aber nur ohne Passwort. So ist der Code fehlerhaft ist, wo ich das Passwort bin hinzufügen. Aber was hat sich zwischen 2003 und 2008 geändert, die es von der Arbeit aufgehört haben würde?

Hier ist mein Code.

Using ldapConn As New LdapConnection(New LdapDirectoryIdentifier(LDAPServerAddress), credential)
 ldapConn.SessionOptions.ProtocolVersion = 3
 ldapConn.SessionOptions.Signing = Not _UseSecureConnection
 ldapConn.SessionOptions.Sealing = Not _UseSecureConnection
 ldapConn.SessionOptions.SecureSocketLayer = _UseSecureConnection
 If _UseSecureConnection Then
  ldapConn.SessionOptions.VerifyServerCertificate = New VerifyServerCertificateCallback(AddressOf ServerCallback)
 End If
 ldapConn.AuthType = AuthType.Negotiate

 ldapConn.Bind()

 Dim DistinguishedName As String = String.Format("CN={0},OU={1},{2}", Me.AccountName, Me.OrgUnit, Me.DCSuffix)

 ' Save this distinguished name to the local object; so that the group memberships addition works in a minute.
 Me._DistinguishedName = DistinguishedName

 Dim addRequest As New AddRequest(DistinguishedName, Me.LDAPUserObjectType)

 '' Add an AccountName attribute
 addRequest.Attributes.Add(New DirectoryAttribute(GetLDAPSchemaMapping(LDAPUserProperties.AccountName), AccountName))

 '' Look in any derived classes, if they want any attributes adding as part of this save operation.

 '' Hint: Derived classes will override the "GetDirectoryAttributesForAddNewRequest" function and return a list of anything they want adding
 '' to the AD at the time of creation.
 If Not GetDirectoryAttributesForAddNewRequest() Is Nothing Then
  For Each kvp As KeyValuePair(Of String, String) In GetDirectoryAttributesForAddNewRequest()
   addRequest.Attributes.Add(New DirectoryAttribute(kvp.Key, kvp.Value))
  Next
 End If

 '' Hash up the password into a Unicode byte array and send this as the requried initial password.
 addRequest.Attributes.Add(New DirectoryAttribute("unicodePwd", GetPasswordData(UsersFirstPassword)))

 ' Execute the request on the directory server.
 Dim addResponse As DirectoryResponse = ldapConn.SendRequest(addRequest)

 ' Need to return the GUID, need to search against the ldap server:
 Dim request As New SearchRequest(String.Format("OU={0},{1}", Me.OrgUnit, Me.DCSuffix), "(&(objectCategory=" & Me.LDAPUserObjectType & ")(sAMAccountName=" & Me.AccountName & "))", System.DirectoryServices.Protocols.SearchScope.Subtree)
 Dim searchResponse As SearchResponse = DirectCast(ldapConn.SendRequest(request), SearchResponse)

 returnedGuid = DirectCast(searchResponse.Entries(0).Attributes("objectGuid").Item(0), Byte())

 ' Set up the search request object so we can do searches now based on this new user:
 Dim rq As SearchRequest = BuildLdapSearchRequest("sAMAccountName", Me.AccountName)

 ' ** Send the query to the LDAP server, and save the response into the private _SearchResponse object **
 _SearchResponse = DirectCast(ldapConn.SendRequest(rq), SearchResponse)
End Using

ist _useSecureConnection false für diesen Aufruf - die Bindung funktioniert gut. Wie ich schon gesagt habe, wenn ich diese Zeile aus kommentieren, es funktioniert:

addRequest.Attributes.Add(New DirectoryAttribute("unicodePwd", GetPasswordData(UsersFirstPassword)))

Die GetPasswordData Methode ist unten auf Vollständigkeit.

''' <summary>
''' Returns a unicode-encoded byte array based on the incoming password string.
''' </summary>
''' <param name="password">The password to turn into a byte array</param>
Public Function GetPasswordData(ByVal password As String) As Byte()
 Dim formattedPassword As String
 formattedPassword = String.Format("""{0}""", password)
 Return Encoding.Unicode.GetBytes(formattedPassword)
End Function

Ich schätze keine Einblicke ...

Viele Grüße bgs264

War es hilfreich?

Lösung 2

Dies wurde durch eine Kombination fixiert LDAPS statt LDAP zu verwenden; die Kennwortrichtlinie entspannen; tut ein voll von der Anwendung neu; den Browser-Cache zu löschen und alle Server neu zu starten.

Andere Tipps

Ist es möglich, dass die Passwort-Richtlinien unterschiedlich sind für die beiden Server? Oder, dass es eine andere Politik Unterschied?

Eine Möglichkeit zur Überprüfung könnte sein, das ldp.exe-Tool zu verwenden und sehen, ob Sie mit ihm die gleichen Operationen mit dem exakt gleichen Passwort tun können. Hier 'sa Link, der beschreibt Ändern Kennwort dieses Werkzeug.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top