This sample will help in connecting to the Active Directory, Authentication the user on the defined Active Directory and get all the users present in the defined groups in Active Directory. This code contains plug and play classes which can be directly placed into an application and can be used. On can also customize them according to the needs.
Working and the Sample Description
This sample to be working you need .Net Framework 4.0. It contains one class library project and one Web site to show the demonstration.Class Library project contains one class named "LDAP.cs", this is the class which is actually interacting with the Active Directory. This project needs a reference of "System.DirectoryServices", so if one wants to interact with Active Directory then the library which will be interacting with Active Directory should have reference to this .Net DLL(s). "LDAP.cs" contains two public methods, one of which authenticates the user and other one helps in retrieving all the users from the Directory. Other class which is present in this library project is the "User.cs" this is the custom class created so as to get the user details from the Active Directory then fill in the details into this class, so as to keep the solution generic as every application has one User Entity of its own.Website contains a sample page and one class which is interacting with the class library.Sample page will demonstrate the Authentication logic along with the logic of getting users from the Active Directory in a particular group. Last is the application settings key added into "Web.config".First one is "ActiveDirectoryPath" - This will contain the path to your Active DirectorySecond is "DomainName" - This is the domain on which your Active Directory is present.Third and the last is the "ActiveDirectoryGroups" - This will contain all the groups for which you want to retrieve users from Active Directory. If you have multiple groups then you can give the Group name(s) as pipe("|") separated.
<appSettings><!--Active Directory Path -->
<add key="ActiveDirectoryPath" value=""/>
<!--Domain Name -->
<add key="DomainName" value=""/>
<!--User Groups for which search needs to be performed, User groups are Pipe Separated. example: "Admin|Guest" -->
<add key="ActiveDirectoryGroups" value=""/>
For Downloading the code, please refer the following URL: Source Code
I welcome some valuable feedback.
So to get it working you just need to make changes in Web.Config and the sample will be running....
Post a Comment