473,486 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem updating Active Directory from code

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.T oString()
Dim searchRoot As New DirectoryEntry("LDAP://" & namingContext)
Dim searcher As New DirectorySearcher
searcher.SearchRoot = searchRoot
searcher.Filter =
String.Format("(&(objectCategory=person)(objectCla ss=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()
Nov 18 '05 #1
1 1739
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
"Robin" <ro*******@hotmail.com> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
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.T oString()
Dim searchRoot As New DirectoryEntry("LDAP://" & namingContext)
Dim searcher As New DirectorySearcher
searcher.SearchRoot = searchRoot
searcher.Filter =
String.Format("(&(objectCategory=person)(objectCla ss=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()


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4908
by: Dave | last post by:
Hello. I am trying to update attributes in LDAP/Active directory from my application that is written in VB.NET. I am using Directory Services to do so. I do not get any errors during the...
1
4731
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
0
1628
by: Tim::.. | last post by:
Hi... I'm having a big problem with a datagrid that obtains data from 2 different locations... Active Directory and SQL Database The data is inserted into a datatable and the sorted by a...
4
336
by: Dave | last post by:
Hello. I am trying to update attributes in LDAP/Active directory from my application that is written in VB.NET. I am using Directory Services to do so. I do not get any errors during the...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.