google407ec42f1ae5ff0e.html
top of page

Create a Active Directory Connection in asp.net and fetch all user details in Grid View

namespace WebApplication9

{

public partial class _Default : Page

{

protected void Page_Load(object sender, EventArgs e)

{

DirectoryEntry entry = new DirectoryEntry(ConfigurationManager.AppSettings["LDAP://domainname/"]);

DirectorySearcher search = new DirectorySearcher(entry)

{

SearchScope = SearchScope.Subtree,

Filter = "(&(objectClass=user)(objectClass=person))"

};

search.PropertiesToLoad.Add("sAMAccountName");

SearchResultCollection result = search.FindAll();


var users = result.Cast<SearchResult>().Select(sr => sr.GetDirectoryEntry())

.Select(de => new

{

Name = de.Properties["Name"] != null ? de.Properties["Name"].Value.ToString() : "",

//Phone = de.Properties["Phone"] != null ? de.Properties["Phone"].Value.ToString() : "",

//Email = de.Properties["Email"] != null ? de.Properties["Email"].Value.ToString() : "",

}).ToList();


GridView1.DataSource = users;

GridView1.DataBind(


}

8 views0 comments

Recent Posts

See All

Commenti


bottom of page