C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to display user’s full name using Active directory?


Posted Date: 31 Mar 2008    Resource Type: Articles    Category: Web Applications

Posted By: Aravind PK       Member Level: Gold
Rating:     Points: 10



how to...


First of all, we need to know what Active directory is. Here in this post, I am not going to provide information about Active Directory. Please see yourself about Active Directory or let me post about that later.

Its all simple to create a home page or any site displaying the user name without any input from user to provide, but all these are possible only for Intranet Websites only.

Things you require:


Namespaces:
using System.DirectoryServices;
using System.Security.Permissions;


You need to know your LDAP Path of your company active directory. Then add that LDAP Path in web.config file as


value="LDAP://domain-ip or address/DC=domain,DC=com"/>



Then in page_load() event, try this code. The code shown below will do the following:
1) Gets the LDAP path from web.config into a local variable.
String LDAPpath = System.Configuration.ConfigurationSettings.AppSettings["LDAPpath"];


2) Now identifying the windows identity credentials of the currently logged in user details.
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();


3) The string array “a” will contain the domain name and the user name in which name the user is logged in.
string[] a = Context.User.Identity.Name.Split('\\');


4) Getting the instance of the directory entry from the user name and the domain name which is available from the string array “a”.
System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);


5) Getting the “full name” of the currently logged in user, using the property string of the directory entry.
string Name = ADEntry.Properties["FullName"].Value.ToString();
Response.Write("
" + Name + "
");


6) You can also look around the complete set of properties the directory entry has, by using this code.
foreach (string Key in ADEntry.Properties.PropertyNames)
{
string sPropertyValues = String.Empty;
foreach (object Value in ADEntry.Properties[Key])
{
sPropertyValues += Convert.ToString(Value) + ";";
}
sPropertyValues = sPropertyValues.Substring(0, sPropertyValues.Length - 1);
Response.Write("key:" + Key + "-Value:" + sPropertyValues);
}


Conclusion


This may help you show your required information on the page about the user who logged into that machine.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Update the Datatable to SQLTable
Previous Resource: LINQ Introduction
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use