Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

To get userdetails from Acive directory

$
0
0

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 =newDirectorySearcher(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


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>