retrieve user info from user directory

Cryingi have to retrieve user information from active directory in ASP.NET by passing employee id to it.

i'm building an web application usinf visual studio 2008 and C#. Can anyone plz give me some information on how shoiud i do this

 

 

0
rakeshadiga
11/24/2008 10:27:47 AM
asp.net.active-directory-ldap 2291 articles. 0 followers. Follow

9 Replies
667 Views

Similar Articles

[PageSpeed] 31

 Hi, please go through the sample code below..

 

 
 public static DirectoryEntry GetDirectoryEntry(string DomainReference)
    {
        string ADFullPath = "LDAP://domainName.com";
        DirectoryEntry de = new DirectoryEntry(ADFullPath + DomainReference, UserName, Password, AuthenticationTypes.Secure);
        return de;
    }

    private static string GetLDAPDomain()
    {
        StringBuilder LDAPDomain = new StringBuilder();
        string[] LDAPDC = "domainName.com".Split('.');
        for (int i = 0; i < LDAPDC.GetUpperBound(0) + 1; i++)
        {
            LDAPDomain.Append("DC=" + LDAPDC[i]);
            if (i < LDAPDC.GetUpperBound(0))
            {
                LDAPDomain.Append(",");
            }
        }
        return LDAPDomain.ToString();
    }

 
 

put this piece of the code in page load or a button clcik

                     

DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(employeeID=" + txtEmployeeID+ ")"; // pass the employeeID
search.PropertiesToLoad.Add("name");
search.PropertiesToLoad.Add("email");
search.PropertiesToLoad.Add("description"); // load what properties based on your requirement...

SearchResult result = search.FindOne();
 
 txtEmailDisplay.Text=result .Properties["email"][0].ToString();
TextBox2.Text=result .Properties["name"][0].ToString(); 
 
PLease get back to me if you have any more querries... 
 

Thanks and Regards
Nimesh Prabhakar


Mark this post as "ANSWER", if it helped you..
0
nimeshprabhakar
12/1/2008 11:35:18 AM

hiiiiiiiiiiiiiiii..............nimesh.................. thank u sooooooomuch..i'll check the code right away and tel whether i got what i wanted or not..

alos i need a lot of help from u..stay in touch...

my application requires user to fill login webpage with username , passworr, at backend i need to store his data( name, mail id , phone No) from server into a database table...

i'll fill u with more queries,.....

0
rakeshadiga
12/2/2008 3:11:59 AM

hi nimesh, what values should i pass for these ????   DomainReference, UserName and Password......

wheterh i pass my Uname and password  or wat ??   also in  "txtEmployeeID"  whose id i sholid pass, the employee whose id i'm searching details...rite ???????

 

reply  ASAP

0
rakeshadiga
12/2/2008 4:07:39 AM

 

 string ADFullPath = "LDAP://YourDomianName";  //Put your domain name here.. The bold part
and regarding the username and password: Ask your IT team or someone to create a user with never expire password.
for the time beign, you can use your username and apssword.
rakeshadiga:
"txtEmployeeID"  whose id i sholid pass, the employee whose id i'm searching details...rite ???????
 
ofcourse the employee ID you wanna search. 

 

For eg:

 Let your domain name be Domain,Username :rakesh, Password: rakesh123
so your code wil be somethign like this:

public static DirectoryEntry GetDirectoryEntry(string DomainReference)
{
string ADFullPath = "LDAP://Domain.com"; DirectoryEntry de = new DirectoryEntry(ADFullPath + DomainReference, rakesh, rakesh123, AuthenticationTypes.Secure);
return de;
}
  
 private static string GetLDAPDomain()
    {
        StringBuilder LDAPDomain = new StringBuilder();
        string[] LDAPDC = "Domain.com".Split('.');
        for (int i = 0; i < LDAPDC.GetUpperBound(0) + 1; i++)
        {
            LDAPDomain.Append("DC=" + LDAPDC[i]);
            if (i < LDAPDC.GetUpperBound(0))
            {
                LDAPDomain.Append(",");
            }
        }
        return LDAPDomain.ToString();
    }
 
and the rest of the codes.... this is all that you need to run the part of the code...
inorder to access the active directory you need a username and password as well as domain name.
To get more idea about the AD, you can download Active Directory Expolrer from Microsoft. 
Login using your DomainName, your own windows authentication username and password
 Some of the links i am providing here, will help you a lot..
http://www.primaryobjects.com/CMS/Article61.aspx 
http://www.vbforums.com/showthread.php?t=415856         

http://www.willasrari.com/blog/query-active-directory-users-using-c/000133.aspx

http://www.codeproject.com/KB/system/everythingInAD.aspx#22 

http://www.dotnetactivedirectory.com/Accessing%20LDAP%20Active%20Directory%20from%20C%20Sharp%20or%20VB%20.NET%20Code.html#%20or%20VB%20.NET%20Code.html
 
 
 
pls get back to me if you hjave any more querries 
 
Thanks and Regards
Nimesh Prabhakar


Mark this post as "ANSWER", if it helped you..
0
nimeshprabhakar
12/2/2008 8:58:20 AM

 

Can we retireve a users details from active directory using his name attribute???
0
seebharath
12/5/2008 6:38:43 AM

Got to do it ..

Feels great!!

All that i needed to do was to change the parameter on which i was searching in Active Directory...

0
seebharath
12/7/2008 12:49:39 PM

 please mark the post which answered your question and close this thread...


Thanks and Regards
Nimesh Prabhakar


Mark this post as "ANSWER", if it helped you..
0
nimeshprabhakar
12/8/2008 4:19:15 AM

Hey man i did,nt start this thread...Indifferent

Anyways those urls helped me a lot in finding the answers....

Thanks Nimesh....

0
seebharath
12/8/2008 8:54:02 AM

 i didnt mean u.. i asked the person who has started the thread....

Smile 


Thanks and Regards
Nimesh Prabhakar


Mark this post as "ANSWER", if it helped you..
0
nimeshprabhakar
12/8/2008 11:29:37 AM
Reply:

Similar Artilces:

Return All Users with User Groups from Active Directory with LDAP
Hello.  I am trying to write a report that pulls information in from Active Directory.  I have a view created that gets a listing of users and a view that creates a listing of user groups, but I can't seem to figure out how to get all user groups that are associated with the users.  This is what I have. SELECT     *FROM         OPENQUERY(ADSI, 'SELECT objectSid, samAccountName, distinguishedName FROM ''LDAP://wmdomain.local''WHERE objectClass = ''User''')    ...

Active Directory, retrieving user info
Hello, Using old Agnisoft unit I am trying to connect from a Windows 7 machine to a Windows 2003 server running AD and then retrieve some information about the current user logged into the Win7 machine (like what group it belongs, etc). The trouble is that everytime I got "Access Denied" when trying to access anything user related. A sample of the code below: try ADPath := 'WinNT://WIN2030'; ADsGetObject(ADPath, IADSContainer, dom); -> works fine, if wrong network path it will raise exception IADs(dom.GetObject('user', 'test_user')); -> excep...

Net::LDAP, Active Directory and Disabled Users
------_=_NextPart_001_01C386CB.502F3B30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've been trying to write a simple perl script that will query the = active directory via LDAP and give me a list of email addresses for disabled = users (eg, addresses we don't want to accept email for anymore). I found a = website or two that suggested I use the following as my filter: (&(objectCategory=3Dperson)(userAccountControl:1.2.840.113556.1.4.803:=3D= 2)) I was beginning to think these websites were wrong as whene...

Net::LDAP, Active Directory and Disabled Users #2
I've been trying to write a simple perl script that will query the active directory via LDAP and give me a list of email addresses for disabled users (eg, addresses we don't want to accept email for anymore). I found a website or two that suggested I use the following as my filter: (&(objectCategory=person)(userAccountControl:1.2.840.113556.1.4.803:=2)) I was begining to think these websites were wrong as whenever I tried this filter, I'd go no results. With other filters, I'd get the results I'd expect to get. I then tried that filter in a couple other appli...

Active Directory: Retrieve User Info Only on Local Machine?
In my web application, I'm trying to retrieve the user's first name, last name, and email address from Active Directory when the user logs-into my web application. To do so, I've used this code which fires when the application starts: <a href="http://www.123aspx.com/redir.aspx?res=30841" target="_blank">http://www.123aspx.com/redir.aspx?res=30841<a> The problem I have is that this code only seems to work on my machine? I have my browser set to auto-login to Intranet Zones. When I login to my own PC as various users, the codes seems to work and my appl...

RE: Net::LDAP, Active Directory and Disabled Users
Version of Perl:=20 5.8.0 (as supplied with RedHat9) Version of Net::LDAP: [jsteenha@jake utilities]$ perl -mNet::LDAP -e 'print = "$Net::LDAP::VERSION\n"' 0.29 Relevant part of Perl code: #!/usr/bin/perl use Net::LDAP; use Net::LDAP::Filter; $filter =3D = '(&(objectCategory=3Dperson)(userAccountControl:1.2.840.113556.1.4.803:=3D= 2))'; #$filter =3D '(objectCategory=3Dperson)'; $f =3D new Net::LDAP::Filter; $f->parse($filter); $f->print(); #exit; my $ldap =3D Net::LDAP->new('acutex-dc01'); my $mesg =3D $...

Active Directory user home directory
Hi all. I have a question, how to sync home directorires of users from Identity Vault to Active Directory? Into AD there are 2 LDAP attributes calleds homeDrive (the network drive letter) and homeDirectory that is the network path used to map during user login. My doubt is about the eDirectory volume information. The volume will be not sync to the AD because AD does not recognize this information, right? So, how to sync? I was thinking about create 2 eDirectory attributes where I can write theese informations. What do you think about this? Anyone can help me? Best regards...

Is there a way to authenticate Active Directory users from multiple Active Directory Domains
Is there a way to authenticate Active Directory users from multiple Active Directory Domains in ASP.NET Application using C# or VB.NET?Suppose I have a LoginId "user1" from one of the three Active Directory Domains how can I authenticate it?I have two Active Directory domains. I can authenticate from the Active Directory Domain where my current system Account is logged in. But I can not authenticate from other Active Directory Domains. Actually I have 2 Active Directory domains in my LAN.Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])Netprosys Inc.ww...

How to check the username with active directory and fetch the user details from the active directory?
I have a textbox with a submit button.When the admin types the username in the textbox and submits it has to check with active directory and fetch the firstname and last name of the user entered inthe textbox.How will i do this one.Code is appreciated. you will find lot of samples if you search for "ActiveDirectory using .NET" but here is a verysimple code and it works too:-) strLANID = "ADDomainName\user"           Dim dservices As New System.DirectoryServices.DirectoryEntry        ...

Membership Users not matching Active Directory users
I'm having trouble w/ my intranet security using window authentication. When I get the User.Identity.Name it returns Domain\UserName. However, I'm using AspNetSqlRoleProvider and when I assign roles using the asp net website administration tool, my users appear as UserName@Domain.com. Then when I add users to roles and apply security to folders, users can still access those folders. Is this because the UserNames are not matching? My Roles and Membership appear to talking, but passing the wrong username? Also if i try and find myself in "Administors" user.isinrole, i am not in any role. I'm ...

Active Directory
Could somebody please point me in the right direction?  I'm attempting to make a website pulling information from active directory.  I am able to pull specific user information using VBS but am very lost as to how to port this type of stuff over to a website.  Could somebody please post some examples or websites showing how to display maybe just all users from AD? Thanks so much. ...

Retrieve All users from Active Directory
I need to retrieve all the users from Active Diretory. I know how to search one user but not to retrieve all. I have multiple OU hierarchies.The scenario is I have about 40 different OUs under root OU. There are again sub ou's under each OU. please let me know if you have any suggestions. I haven't tried it, but google search brought this http://www.codeproject.com/KB/aspnet/adsi2.aspxBeware of bugs in the above code; I have only proved it correct, not tried it. (Donald Knuth) Check out: http://forums.asp.net/t/907421.aspx...

how to create AD users in 'Users' section of "Active Directory Users and Computers" window.
 I can create new AD users but not in 'Users' section in "Active Directory Users and Computers" window of windows server 2003.Here is the related part of my code: System.DirectoryServices.DirectoryEntry myAD = new DirectoryEntry("LDAP://" + xxx + "/Users"); //If I put "/Users" then it throws exception, otherwise it works. But, users are not created in 'Users' folder. DirectoryEntry newUser = myAD.Children.Add("CN=" + username, "user"); newUser.Properties["d...

Reading active directory user id for a user group
I need to write a function that accepts active directory user group and return all the users belong to that group. My function so far returns user fist name, last name and so on except userid. I am not sure how to retreive that.  Dim path As String = "LDAP://asd.dev.com"        Dim entry As DirectoryEntry = New DirectoryEntry(path)        Try            'Dim native As Object = entry.NativeObject             ...

Web resources about - retrieve user info from user directory - asp.net.active-directory-ldap

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Wikipedia:WikiProject Council/Directory - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory
... continue reading at 9to5Mac . What do you think? Discuss "LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory" ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Amazon brings Microsoft users into AWS with Active Directory service
Amazon has launched an AWS Directory Service for Active Directory , a fully managed implementation of Microsoft's authentication and user management ...

Researchers find way to steal Windows Active Directory credentials from the Internet
The technique could enable attackers to attack Windows servers hosted in the cloud

NorthPark at 50: Store directory from mall’s 1965 opening is a blast from the past
Grab a glass of wine, get on the phone with your best girlfriend from high school and check out this original map/directory of NorthPark Center. ...

Azure Active Directory Enables One-Step MDM in Windows 10
DAILY VIDEO: Microsoft enables one-step MDM in Windows 10; IRS breach more extensive than first reported; Georgia Tech finds 11 deep security ...

Resources last updated: 12/9/2015 2:55:12 PM