User-170024082 posted
hi,
I am working on access user details from Active directory. I have tried this below code. but when I trying to access the user details, I am not getting any result. Please verify the code below and let me know if I missed any point.
Code
void Button1_Click(object
sender, EventArgs e)
{
string connection =
ConfigurationManager.ConnectionStrings["ADConnection"].ToString();
DirectorySearcher dssearch =
new
DirectorySearcher(connection);
dssearch.Filter ="(sAMAccountName="
+ txtusername.Text + ")";
//SearchResult sresult = dssearch.FindAll();
SearchResult sresult
= dssearch.FindOne();
DirectoryEntry dsresult = sresult.GetDirectoryEntry();
lblfname.Text = dsresult.Properties[
"givenName"][0].ToString();
//lbllname.Text = dsresult.Properties["sn"][0].ToString();
//lblemail.Text = dsresult.Properties["mail"][0].ToString();
}
////////////////////////////////////////////////////////////////////////////////
Webconfig file :
<connectionStrings>
<add name="ADConnection" connectionString="LDAP://OurDomain.com"/>
</connectionStrings>
Thanks,
Rinku