Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to search Active Directory when dialed in remotely?
    text
    copied!<p>Is there a way to use a credential coming from the user's saved password list and use that instead of the local Windows credentials?</p> <p>I need to look up a user's email address based on their Active Directory username to allow them to register for email updates via an intranet site. This seems easy enough if the user is actually logged into a machine directly that's part of the domain - I can use their identity name to search the AD based on their username:</p> <pre><code>using( DirectoryEntry root = new DirectoryEntry("LDAP://admachine.domain.local") ) { using( DirectorySearcher searcher = new DirectorySearcher(root) ) { // strip the domain from the username and find the user in AD var username = Regex.Replace(Page.User.Identity.Name, @".*\\", string.Empty); searcher.ReferralChasing = ReferralChasingOption.All; searcher.SearchScope = SearchScope.Subtree; searcher.Filter = string.Format("(&amp;(objectCategory=user)(objectClass=person)(sAMAccountName={0}))", username); var foundUser = searcher.FindOne(); // error checking occurs here... var email = foundUser.Properties["mail"][0].ToString(); // TODO: stuff with the email address } } </code></pre> <p>However, if working from a PC at home this doesn't work. <code>Page.Identity.Name</code> resolves to the name I'm logged onto my own PC (<code>MyMachine\Dave</code>), ignoring stored credentials I used to authenticate with my work domain (<code>WorkDomain\dave.downs</code>).</p> <p>The <code>DirectoryEntry</code> picks up and uses the saved credential just fine, allowing me to actually bind to and search the AD, but I can't find a way of then using it as the <code>var username</code>, which will contain of my local machine username instead.</p> <p>Is there a way to actually do what I'm trying to do, or am I just going about things the wrong way/hitting my head against a brick wall?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload