What Is Active Directory
An active directory is a directory structure used on Microsoft Windows based computers and servers to store information and data about networks and domains.
To use Active Directory (AD) in ASP.Net, First we have to create “Instance For ADAM” and configuration of it. Then I will create a sample application and explain how to interact ADAM with ASP.Net.
Creating Instance and Configuration:
Install ADAM software. Then select “Create an ADAM Instance” in the start menu.
Select “A Unique Instance”, then give some name to the Instance
Give a Port number, leave default SSL port number.
Select “Yes, to create an application directory partition”.
Here O,DC are the LDAP attributes.
Leave default values for location of data file and backup file.
Provide the account under which this account runs.
It will prompt for confirmation,select “YES”. Then select System
Import all LDIF Files.
Copy contents and paste in a file(notepad, etc)
Click Next which will Instantiate new Instance.
Click Finish. And open ADAM ADSI Edit in start menu.
Right click on ADSI root node and click connect to. And enter the details as.
Right click on Distinguished name and select New -> Object in that one select “Organizational Unit” which for Admin.
Click on Finish. Now right click on the Organizational Unit which is created and select Properties, in that properties select distinguished name property and copy into a notepad.
Right click on new OU(Organizational Unit) and create a new User
Now right click on CN=TestAdminUser and select properties, in that properties change the User Principal Name as
And make the “Don’tExpirePassword” property to false.
Now right click on TestAdminUser and reset the password.
Go to CN=Roles and choose CN=Administrators and choose properties and go to member property.
Click on Add ADAM Account and add the user created above.
Create another Organizational Unit (OU) for the user to create login account programmatically.
Go to Roles and choose CN=Readers and choose properties and then select “member” property. Add ADAM account.
Now open ADAM command prompt and run command “dsmgmt.exe”
Now configure ADAM schema – Password policy setting. Type as “mmc /a”.
Click on File – Add/Remove snap – In and then click on ADD and select ADAM Schema
Select ok, ok. Right Click on ADAM Schema and change the server details. Enter the details of ADAM Instance.
Right click on Attributes and click on create attribute.
Go to Classes Node in the Adam Schema, select User and right click and choose properties and select Attributes tab.
Add all the properties created above.
Go to ADAM ADSI Edit , select the instance and right click on it. In that select Update Schema Now.
Note:I created a document of "ADAM Instance Creation" with all of screen shots. You can find below.
Interacting with ADAM with ASP.Net
Step 1: Create a website and add three pages to the application with name Registration.aspx, Login.aspx, Welcome.aspx.
Step 2: Open Registration.aspx page. Drag “CreateUserWizard” control and set the “ContinueDestinationPageUrl” as “~/login.aspx”.
Step 3: Now open login.aspx page. Drag “Login” control and set the “DestinationPageUrl” property to welcome.aspx. and set “DisplayRememberMe” to false.
Step 4: Now open the web.config file and add the blow mentioned code.
- <appSettings>
- <add key="connectionUsername" value="CN=TestAdminUser,OU=TestAdmin,O=Admtest,DC=Testing,DC=COM"/>
- <add key="connectionPassword" value="hello"/>
- <add key="connectionServer" value="localhost"/>
- <add key="connectionPortNumber" value="50001"/>
- <add key="connectionRoot" value="O=Aest,DC=Testing,DC=COM"/>
- <add key="connectionUsersContainer" value="TestUsers"/>
- <add key="defaultRoles" value="Readers"/>
- <add key="connectionRolesContainer" value="Roles"/>
- <add key="connectionAdminsContainer" value="TestAdmin"/>
- </appSettings>
- <appSettings>
- <connectionStrings>
<add name="TestCon" connectionString="LDAP://localhost:50001/OU=TestUsers,O=Aest,DC=Testing,DC=COM"/>
</connectionStrings>
- <appSettings>
- <machineKey validationKey="51AF1A8093A19043C4AAEC218BC36D9C3299C06AA823DDDAC5877431E7AFE90C1B053057EA760CA4DCC15D3CED15035588BB1B461C959434DE68B8381CDF99AA" decryptionKey="BCE825E1668990B11CE01AFF01C4AFE8D63AE300958A85EC" validation="SHA1"/>
- <membership defaultProvider="MyADAMMembershipProvider">
- <providers>
- <add name="MyADAMMembershipProvider"
- type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
- connectionStringName="TestCon"
- connectionUsername="CN=TestAdminUser,OU=TestAdmin,O=Aest,DC=Testing,DC=COM"
- connectionPassword="hello"
- connectionProtection="None"
- enableSearchMethods="true"
- requiresUniqueEmail="false"
- enablePasswordReset="true"
- requiresQuestionAndAnswer="true"
- attributeMapPasswordQuestion="PasswordQuestion"
- attributeMapPasswordAnswer="PasswordAnswer"
- attributeMapFailedPasswordAnswerCount="BadPasswordAnswerCount"
- attributeMapFailedPasswordAnswerTime="BadPasswordAnswerTime"
- attributeMapFailedPasswordAnswerLockoutTime="BadPasswordAnswerLockoutTime"
- minRequiredNonalphanumericCharacters="0"
- passwordStrengthRegularExpression = "(?=.{7,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@`~$%^+=!*])"/>
- </providers>
- </membership>
Once you modified web.config as like above. Then run the registration page and create a User. If user created succesfully you can find a file created with user name in "TestUsers" section of ADAM.
Note:Add "System.DirectoryServices" assembly reference to your application.
Download ADAM
Download creating ADAM Instance Step by step Document.
Download Sample Application