Problem updating Active Directory from code

R

Robin

When using the following ASP.Net code the error "The directory service
cannot perform the requested operation on the RDN attribute of an object."
is displayed when the commit changes is run. What modifications need to be
made to the code to allow it to update the details?

Dim rootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim namingContext As String =
rootDSE.Properties("defaultNamingContext").Value.ToString()
Dim searchRoot As New DirectoryEntry("LDAP://" & namingContext)
Dim searcher As New DirectorySearcher
searcher.SearchRoot = searchRoot
searcher.Filter =
String.Format("(&(objectCategory=person)(objectClass=user)(samAccountName={0
}))", cUser)
searcher.PropertiesToLoad.AddRange(New String() { _
"name", "givenName", "sn", "initials", "personalTitle",
"extensionAttribute1", _
"department", "title", "description", "info", "roomNumber",
_
"telephoneNumber", "mail", "homePostalAddress",
"extensionAttribute2" _
})

Dim result As SearchResult = searcher.FindOne()

Dim onUser As System.DirectoryServices.DirectoryEntry =
result.GetDirectoryEntry

onUser.Properties("name").Value = NZ(tbPreferredName.Text) ' a text
field

' save details back to AD
onUser.CommitChanges()
 
M

Mary

you need to Bind to the native AdsObject to force authentication.

Dim obj As Object = rootDSE.NativeObject

Dim rootDSE As DirectoryEntry = New DirectoryEntry("LDAP://" & domain,
Usernamewith Domain, password)
'Bind to the native AdsObject to force authentication.
Dim obj As Object = rootDSE.NativeObject
Dim searcher As DirectorySearcher = New
DirectorySearcher(rootDSE )
searcher.Filter = "(SAMAccountName=" & username & ")"
searcher.PropertiesToLoad.AddRange(New String() {"name",
"givenName", "sn", "initials", "personalTitle"})

Dim result As SearchResult = searcher.FindOne()
Dim onUser As System.DirectoryServices.DirectoryEntry =
result.GetDirectoryEntry()
If (result Is Nothing) Then
onUser.Properties("name").Value = NZ(tbPreferredName.Text) '
a
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top