Click here to Skip to main content
12,631,606 members (34,487 online)
Click here to Skip to main content
Add your own
alternative version


86 bookmarked

Authenticating Active Directory user in ASP.NET

, 2 May 2002
Rate this:
Please Sign up or sign in to vote.
How to authenticate the AD user in ASP.NET by using Directory Services


In this article I am concentrating on the validation of the Active Directory user through the ASP.NET pages and in fact you can validate the user in any sort of code (non-ASP.NET). The basic things remain the same but the implementation part will depend on the type of requirement. First of all you need to inclue the following code in the .cs file to freely use the directory services.

using System.DirectoryServices;

This will allow you to get the namespace available in your code. Then to get in to the Active Directory server you need to provide the LDAP path which will find the server from the network. Now this you can will be encapsulated in the DirectoryEntry class. The following code will try to contect the server by the user name and passwords provided by you.

DirectoryEntry entry = new DirectoryEntry(LDAP://ADservername,

As per the user name and password this will give you the abstracted property names and value pair collection. Which you can filter later to find out the information specific to the user. To get the specific information you need the DirectorySercher object which will find all the information you need in name value pairs.

DirectorySearcher mySearcher = new     DirectorySearcher(entry);
    SearchResultCollection results;
    mySearcher.Filter ("name=value");
      results = mySearcher.FindAll();
mySearcher.Filter  ("cn=jignesh");

Over here I try to get the information for the user named jignesh. So for the filter string it is cn=jignesh. This is specific to Active Directory; and you should know all LDAP information about your Active Direcotry. Now is the time to rotate through the name value pair which is quite easy and which you can easily understand.

foreach(SearchResult resEnt in results)
                ResultPropertyCollection propcoll=resEnt.Properties;
                foreach(string key in propcoll.PropertyNames)
                    foreach(object values in propcoll[key])
                        //name and value collection retrival


Thats it. This way you can connect with the server through the LDAP and fetch all the information from that. Like user name password etc. You can set the parameters too.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralASP vs Windows Pin
Anonymous7-Dec-04 9:22
sussAnonymous7-Dec-04 9:22 
GeneralRe: ASP vs Windows Pin
Ryan Fenner12-Sep-05 13:51
memberRyan Fenner12-Sep-05 13:51 
Generalactive directory Pin
DgigoloB22-Nov-04 23:55
memberDgigoloB22-Nov-04 23:55 
Generalproblem with ldap path "LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com" Pin
gautam7924-Jun-04 12:00
membergautam7924-Jun-04 12:00 
GeneralRe: problem with ldap path "LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com" Pin
mpemberton24-Jun-04 13:22
membermpemberton24-Jun-04 13:22 
GeneralRe: problem with ldap path "LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com" Pin
lemravec29-Nov-04 10:09
memberlemravec29-Nov-04 10:09 
GeneralLDAP connection problems Pin
ragibhusain11-Feb-04 7:24
memberragibhusain11-Feb-04 7:24 
GeneralRe: LDAP connection problems Pin
airstep28-Sep-04 8:17
memberairstep28-Sep-04 8:17 
GeneralRe: LDAP connection problems Pin
fdfdfdfdfdfd15-Apr-07 2:13
memberfdfdfdfdfdfd15-Apr-07 2:13 
GeneralFinding groups of logged in user Pin
rdever49-Apr-03 14:48
sussrdever49-Apr-03 14:48 
GeneralRe: Finding groups of logged in user Pin
George Vigelette3-Jun-03 4:56
memberGeorge Vigelette3-Jun-03 4:56 
GeneralRe: Finding groups of logged in user Pin
Anonymous19-Jul-03 23:35
sussAnonymous19-Jul-03 23:35 
GeneralRe: Finding groups of logged in user Pin
Mike-EEEE16-Apr-04 7:08
memberMike-EEEE16-Apr-04 7:08 
GeneralRe: Finding groups of logged in user Pin
superkelvin8823-Jul-09 17:45
membersuperkelvin8823-Jul-09 17:45 
GeneralRe: Finding groups of logged in user Pin
eopie21-Jul-05 14:15
membereopie21-Jul-05 14:15 
GeneralRe: Finding groups of logged in user Pin
Shrijeet3-Aug-05 12:15
sussShrijeet3-Aug-05 12:15 
GeneralRe: Finding groups of logged in user Pin
vincennes22-Oct-12 5:41
membervincennes22-Oct-12 5:41 
GeneralIm trying to figure out a code ... Pin
JeremyDeal18-Dec-02 9:18
memberJeremyDeal18-Dec-02 9:18 
Questionhow can you tell if the userid/password is valid Pin
ssue10-Dec-02 8:54
memberssue10-Dec-02 8:54 
AnswerRe: how can you tell if the userid/password is valid Pin
g.fiorentini9-May-03 6:14
memberg.fiorentini9-May-03 6:14 
GeneralClient certificate Pin
adk19-Nov-02 23:30
memberadk19-Nov-02 23:30 
Generalbookbik_thailand Pin
Anonymous12-Sep-02 0:51
sussAnonymous12-Sep-02 0:51 
Generalprivlages... Pin
Ray Cassick11-Sep-02 11:39
memberRay Cassick11-Sep-02 11:39 
GeneralRe: privlages... Pin
LMenchu16-Nov-04 12:36
memberLMenchu16-Nov-04 12:36 
QuestionAnd without AD? Pin
Anonymous11-Sep-02 10:53
sussAnonymous11-Sep-02 10:53 
AnswerRe: And without AD? Pin
Anonymous19-Mar-03 6:29
sussAnonymous19-Mar-03 6:29 
GeneralOther fields... Pin
Elvis Fernández10-Aug-02 7:51
memberElvis Fernández10-Aug-02 7:51 
GeneralRe: Other fields... Pin
MikDelaney21-Feb-03 6:16
memberMikDelaney21-Feb-03 6:16 
GeneralRe: Other fields... Pin
Suvadip De17-Aug-04 2:54
memberSuvadip De17-Aug-04 2:54 
GeneralRe: Other fields... Pin
lemravec29-Nov-04 10:02
memberlemravec29-Nov-04 10:02 
GeneralRe: Other fields... Pin
norai2-May-05 8:32
sussnorai2-May-05 8:32 
GeneralI got a Doubt... Pin
Elvis Fernández1-Aug-02 10:27
memberElvis Fernández1-Aug-02 10:27 
GeneralRe: I got a Doubt... Pin
Ryan Kelley10-Aug-02 4:49
sussRyan Kelley10-Aug-02 4:49 
GeneralRe: I got a Doubt... Pin
Elvis Fernández10-Aug-02 7:49
memberElvis Fernández10-Aug-02 7:49 
GeneralNice Article Pin
Nick Parker4-May-02 2:38
memberNick Parker4-May-02 2:38 
GeneralRe: Nice Article Pin
Dato7-Feb-03 10:39
memberDato7-Feb-03 10:39 
GeneralRe: Nice Article Pin
Anonymous24-Feb-03 15:44
sussAnonymous24-Feb-03 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 3 May 2002
Article Copyright 2002 by jignesh
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid