Problem updating Active Directory from code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin

    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.Propert ies("defaultNam ingContext").Va lue.ToString()
    Dim searchRoot As New DirectoryEntry( "LDAP://" & namingContext)
    Dim searcher As New DirectorySearch er
    searcher.Search Root = searchRoot
    searcher.Filter =
    String.Format(" (&(objectCatego ry=person)(obje ctClass=user)(s amAccountName={ 0
    }))", cUser)
    searcher.Proper tiesToLoad.AddR ange(New String() { _
    "name", "givenName" , "sn", "initials", "personalTitle" ,
    "extensionAttri bute1", _
    "department ", "title", "descriptio n", "info", "roomNumber ",
    _
    "telephoneNumbe r", "mail", "homePostalAddr ess",
    "extensionAttri bute2" _
    })

    Dim result As SearchResult = searcher.FindOn e()

    Dim onUser As System.Director yServices.Direc toryEntry =
    result.GetDirec toryEntry

    onUser.Properti es("name").Valu e = NZ(tbPreferredN ame.Text) ' a text
    field

    ' save details back to AD
    onUser.CommitCh anges()


  • Mary

    #2
    Re: Problem updating Active Directory from code

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

    Dim obj As Object = rootDSE.NativeO bject

    Dim rootDSE As DirectoryEntry = New DirectoryEntry( "LDAP://" & domain,
    Usernamewith Domain, password)
    'Bind to the native AdsObject to force authentication.
    Dim obj As Object = rootDSE.NativeO bject
    Dim searcher As DirectorySearch er = New
    DirectorySearch er(rootDSE )
    searcher.Filter = "(SAMAccountNam e=" & username & ")"
    searcher.Proper tiesToLoad.AddR ange(New String() {"name",
    "givenName" , "sn", "initials", "personalTitle" })

    Dim result As SearchResult = searcher.FindOn e()
    Dim onUser As System.Director yServices.Direc toryEntry =
    result.GetDirec toryEntry()
    If (result Is Nothing) Then
    onUser.Properti es("name").Valu e = NZ(tbPreferredN ame.Text) '
    a
    End If


    "Robin" <robin9876@hotm ail.com> wrote in message
    news:e6WTF9AREH A.3628@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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.Propert ies("defaultNam ingContext").Va lue.ToString()
    > Dim searchRoot As New DirectoryEntry( "LDAP://" & namingContext)
    > Dim searcher As New DirectorySearch er
    > searcher.Search Root = searchRoot
    > searcher.Filter =
    >[/color]
    String.Format(" (&(objectCatego ry=person)(obje ctClass=user)(s amAccountName={ 0[color=blue]
    > }))", cUser)
    > searcher.Proper tiesToLoad.AddR ange(New String() { _
    > "name", "givenName" , "sn", "initials", "personalTitle" ,
    > "extensionAttri bute1", _
    > "department ", "title", "descriptio n", "info",[/color]
    "roomNumber ",[color=blue]
    > _
    > "telephoneNumbe r", "mail", "homePostalAddr ess",
    > "extensionAttri bute2" _
    > })
    >
    > Dim result As SearchResult = searcher.FindOn e()
    >
    > Dim onUser As System.Director yServices.Direc toryEntry =
    > result.GetDirec toryEntry
    >
    > onUser.Properti es("name").Valu e = NZ(tbPreferredN ame.Text) ' a[/color]
    text[color=blue]
    > field
    >
    > ' save details back to AD
    > onUser.CommitCh anges()
    >
    >[/color]



    Comment

    Working...