ASP.NET LDAP DirectoryEntry query failed

I have users connecting to my application through Active Directory and then pulling information from their AD to get information about that user:

Dim ID as FormsIdentity = DirectCast(User.Identity, FormsIdentity)
Dim ticket as FormsAuthenticationTicket = ID.Ticket
Dim adDirectory as New DirectoryEntry("LDAP://DC=my,DC=domain,DC=com")
Dim adTicketID as String = ticket.Name.Substring(0, 5)
Session("people_id") = adDirectory.Children.Find("CN=" & adTicketID).Properties("employeeID").Value
Session("person_name") = adDirectory.Children.Find("CN=" & adTicketID).Properties("displayName").Value

      

Now I want to be able to impersonate other users ... so I can "test" the application as theirs, so I added a textbox and a button to the page, and when the button is clicked, the text is assigned to the session variable:

 Session("impersonate_user") = TextBox1.Text

      

When the page reloads, I check to see if the Session ("impersonate_user") has a value other than "" and then tries to query Active Directory using that session variable like this:

If CStr(Session("impersonate_user")) <> "" Then
  Dim adDirectory as New DirectoryEntry(LDAP://DC=my,DC=domain,DC=com")
  Dim adTicketID as String = CStr(Session("impersonate_user"))
  Session("people_id") = adDirectory.Children.Find("CN=" & adTicketID).Properties("employeeID").Value
  Session("person_name")= adDirectory.Children.Find("CN=" & adTicketID).Properties("displayName").Value
Else
  [use the actual ticket.name to get this info.]
End If

      

But it doesn't work. Instead, it throws an error on the first line of the session, which says "The DirectoryServicesCOMEx error was not handled by user code. There is no such object on the server." What for? I know I am giving it a valid username! Is something weird going on during the casting session? The code is essentially the same between each method, except it's in one method, rather than pulling from a ticket. The name I am pulling from the login session variable that I will be looking for using AD.

+2


a source to share


1 answer


Is it possible that your process is running under active directory access rights. You can do this by changing the id your application is running in in the IIS application pool.



What is entered in the text box?

-1


a source







All Articles