[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1154
  • Last Modified:

Use DirectoryServices DirectoryEntry without passing userid or password.

I am trying to use the DirectoryServices' DirectoryEntry class to retrieve the email address for a given user. I do not want to pass a user id/password, but would rather use windows authentication. The only way I could get it to work though is to pass a valid user and password. Is there a way to do this without a userid/password?

Dim adPath As String = String.Format("LDAP://<SID={0}>", userSid)
        'Create DE object
        Dim sidBind As DirectoryEntry = New DirectoryEntry( _
            adPath, _
            "", _
        'retrieve e-mail address property
        If sidBind.Properties.Contains("mail") Then
            Return sidBind.Properties("mail").Value.ToString()
            Return String.Empty
        End If

Open in new window

1 Solution
Sreedhar VengalaCommented:
<authentication mode="Windows" />
<identity impersonate="true"/>
and by passing : User.Identity.Name
further check : http://aspalliance.com/553
MikeBroderickAuthor Commented:
That did it. One of my attempts would have worked except I passed "" (null string) as the password instead of the keyword nothing:
            Dim sidBind As DirectoryEntry = New DirectoryEntry( _
                adPath, _
                LogInName, _
                Nothing, _

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now