Last post Jan 20, 2010 01:32 PM by niravparekh
Jan 12, 2010 09:56 AM|niravparekh|LINK
Hi, I am getting user's information from Active Directory by his entered Email Address.
Now, I want to know what is his log in credentials, I mean like Identity.Name which displays Domain\UserName.
Can someone tell me what is the return attribute name that I can add in my function to get the DomainName\UserName for given Email Address?
Just for information, here is my basic function that I am using to get information about user from Active Directory and I want to add this attribute\property to get his domainname\username.
public bool IsAuthenticated_CheckWithEmail(
DirectoryEntry entry = new DirectoryEntry();
entry = new DirectoryEntry(_path);
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(mail=" + email + ")";
search.PropertiesToLoad.Add("cn"); // Login Name
search.PropertiesToLoad.Add("givenName"); // First Name
search.PropertiesToLoad.Add("sn"); // Last Name
search.PropertiesToLoad.Add("displayName"); // Display Name
search.PropertiesToLoad.Add("memberof"); //Get User Groups
SearchResult result = search.FindOne();
if (null == result)
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"];
FirstName = (String)result.Properties["givenName"];
LastName = (String)result.Properties["sn"];
EmailAddress = (String)result.Properties["mail"];
//TODO: find out attribute name for this to get domain/username
//UserName = (String)result.Properties["cn"];
UserDisplayName = (String)result.Properties["displayName"];
TelephoneNumber = (String)result.Properties["TelephoneNumber"];
catch (Exception ex)
throw new Exception("Login Error: " + ex.Message);
Jan 12, 2010 01:14 PM|wtroom|LINK
I don't think it puts the domain name in front of it (i..e, DOMAIN\samAccountName). Here is a blog I wrote on querying AD from SQL 2005. I am posting this because there are field names in my post so it may help you out.
Jan 12, 2010 02:48 PM|niravparekh|LINK
I tried samAccountName but it does not include domain name.
I am looking for the prpperty name which displays "DomainName\SamAccountName".
Jan 12, 2010 03:37 PM|wtroom|LINK
Ok, I didn't think there was a property that included the domain name, just the login name. I'd be curious to see what other say or find. Is there a reason you don't want to append that part of the string since you need that value to do your AD search anyway?
Here is a link I found as well, but it doesn't look like it provided a full solution. However there is a link in that thread pointing on how to grab the netBIOS name of the domain.
Jan 20, 2010 01:32 PM|niravparekh|LINK
I am extreme sorry for late reply.
ok, I can use SAMAccountName and can append it but then the question is how do I get DomainName? I mean using which property?
If I can get SamAccountName and Domain from different properties, I can surely combine it for my purpose.