How to get domain user's first name, last name and e-mail address

Hi everyone,

I am able to retrieve the domain/user ID by setting <authentication mode="Windows"/> in the Web.config file, and with the following code in my Default.aspx.,cs page:

string strName = Request.ServerVariables["AUTH_USER"];

I would also like to retrieve the users first name, last name and e-mail address from their domain profile, if possible.  Can anyone help me with a code example?  I'm somewhat new to C#/.NET/OOP so if you have it in "C# for Dummies" format, I would be very thankful! Smile

Thanks in advance for any help that is provided!

0
BradAmodeo
4/20/2009 3:41:20 PM
asp.net.security 27051 articles. 1 followers. Follow

5 Replies
1389 Views

Similar Articles

[PageSpeed] 27

Check out this thread: http://forums.asp.net/t/1356629.aspx

Specifically 2nd post in that thread by guru_5F00_sarkar.


Jack Yang
.NET Developer
0
jackyang
4/20/2009 7:30:23 PM

Request.ServerVariables : This is for checking who is trying to log into your application from the server. If you want to get information of the users from domain (LDAP), you can refer to what jack said above. You can't get email address and other information from server variables.


Thanks,
Surya Prakash Jayanti
http://suryaprakashj.blogspot.com
http://jnsuryaprakash.blogspot.com
http://sqlserver-qa.net/blogs/dotnet_40/default.aspx

p.s. Please click "Mark as Answer" if you think this post answered your question
0
jnsuryaprakash
4/20/2009 7:48:03 PM

Thanks Jack!  I gave it a try using the code as is, but it doesn't like:

      using (DirectoryEntry root = new DirectoryEntry(rootQuery))

or

     searcher.Filter = searchFilter;

 VS.NET says that rootQuery and searchFilter do not exist in the current context.  Any ideas?  I think I'm close!

 

Thanks,

Brad

0
BradAmodeo
4/20/2009 9:24:08 PM

Brad, there maybe various reasons that you cannot access certain DirectoryEntry.

First check if rootQuery is defined, an example of how it is look like:  

"LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Developers,OU=Accounts,DC=developer,DC=hamilton,DC=com"
More examples can be found here: http://geekswithblogs.net/mhamilton/archive/2005/10/04/55920.aspx

Secondly, make sure your LDAP access account has enough privilege to actually query the ActiveDirectory. Usually we define a service account and impersonate this special account to traverse ActiveDirectory. See ref: http://msdn.microsoft.com/en-us/library/72wdk8cc(VS.71).aspx

Or it could be settings inside IIS need to be adjusted properly: http://forums.iis.net/t/1144412.aspx


Jack Yang
.NET Developer
0
jackyang
4/21/2009 1:23:09 AM

Thanks again Jack.  Your help is greatly appreciated!

0
BradAmodeo
4/21/2009 3:52:53 PM
Reply:

Similar Artilces:

Getting the user's first and last name
I'm using the login control and I'm getting the username without a problem (<asp:LoginName ID="LoginName1" runat="server" />) but how do I get the user's first and last name (or any other information)?  I do have the user's information stored in a database.  I'm not utilizing Profile schema either.Thanks. Use the MemberShip class to get the user information. http://msdn.microsoft.com/en-us/library/tw292whz.aspx*** If this post helps you, then Mark this post as Answer ***...

Getting user's first and last name from AD
I have an intranet site running with windows authentication, and I would like to greet the user with their full name. What's the best way to find the first and last name values entered in the AD database?I guess it needs a DirectorySearcher object, but my AD knowledge stops there.Thanks,JohnJohn HogeSeaEagle.com Inflatable Boats You can get the current user's details by parsing their domain name and performing a search for it.  Here is an example - 'sn' and 'givenName' are last name and first name respectively.<%@ Assembly Name="System.DirectoryServices, Version=1.0.5000.0, Cultur...

Get user's first and last name from Active directory.
Hi,I'm trying to get user's first and last name from AD to display in my welcome page. I'm using Visual Studio 2005. In my login page I have login control and I'm using forms authentication against LDAP.So I don't have to store user data. Any help would be greatly appreciated.   DirectoryEntry objOU = new DirectoryEntry(",%20DC=domain,%20DC=something,%20DC=net%20or%20com>/">LDAP://CN=your user name, OU=users group>, DC=domain, DC=something, DC=net or com"); string name = objOU.Properties["givenName"].Value.ToString(); string...

Getting first name and last name from Windows logged in user
 I'm sure there must be an easy way of getting the actual first name and last name from an Windows domain\username via the Windows Identity or Principal object, but I can't seem to figure it out. Does anyone have any examples of this? try this: HttpContext.Current.User.Identity.Name  Thanks - tried that...it returns nothing or domain\loginName :( Please check that on the site properties window (in IIS Admin console), in the security tab, click on the modify or edit button in the authentication and anonymous access group and make sure only the "Windows Inte...

User's first and last name
What would be the simplest way to add the user's first and last name to the registration process?I noticed there was a comment column in membership user.  Would it be easy to add xml document to this field?Thanks!Rob you can check the link below:Extend the MembershipUser class http://forums.asp.net/43/ShowForum.aspx...

Open file in browser or application getting the page's name as the file's name
Hi, I'm am trying to get a file to open in either a browser or application depending on the mime type. I'am using the following code in the page load. protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack)    { DocumentInfo document = (DocumentInfo)Session["View_Document"]; StreamFile(document.Document, document.DocumentName, document.FileType.MimeType); } } }private void StreamFile(byte[] fileData, string originalFileName, string mimeType) { try { Response.Clear(); Response.ContentType = mimeType; Response.AddHeader("Con...

Address book is displaying Last Name, First Name and messing up name completion
How do I change my address book so that the name completion looks at First Name, Last Name??? It sounds simple, but I have two computers with the Last Name, First name and it is a pain with the name completion enabled. Thanks Address Book, View, Name Format Cheers Dave -- Dave Parkes [NSCS] Occasionally resident at http://support-forums.novell.com/ Two things I don't like about the firstname, lastname/lastname, firstname thing: 1) With shared address books, an individual user cannot choose which way it goes. 2) Name completion search won't find it...

Comparing a user's name/email to membership user name/email
I want to compare a user's name and email that he/she has entered. If it is correct I want to send an email to the Admin to let them know that they need their password reset. I have the following but for some reason it keeps hitting the else statement: If txtUserName.Text.Length > 25 Then lblOutput.Text = "User's Name is too long!" ElseIf txtEmail.Text.Length > 45 Then lblOutput.Text = "User's Email is too long!" Else Dim strUserName As String = Trim(txtUserName.Text) Dim strEmail As String = Trim(txtEmail.Text) Dim mu As MembershipUser = M...

Last Name only shows up in user's inbox and mail sent from him, after P.O. move
Hi all, I'm having a strange problem with a user's account. We are running 6.5.3 for the client and backend. I just moved this user's account from one P.O. to another. The move went without a hitch, as far as I could tell; it completed normally. That was on Friday (3 days ago). This morning, the user emailed me to tell me that everyone he sends email to only sees his last name in the From field. I was able to see the same thing when he emailed me...his first name no longer appears. I looked at the forums, but only saw postings pertaining to proxying to an account and seeing that happen. Anyone seen my situation before? Know what I can do to fix this? I have tried the usual Sychronize, Structural Rebuild, and Analyze/Fix user database, to no avail. What is odd is that the address book shows his entire last name, but the report from the Analyze/Fix user db shows "Updating entry for lastnamehere", not the full name. Thanks in advance for any help you can provide! Eddie Check eDirectory. The eDirectory object. "Steddie" <hotnix93@juno.com> wrote in message news:a7_8i.10565$Gp4.8713@prv-forum2.provo.novell.com... > Hi all, > > I'm having a strange problem with a user's account. We are running 6.5.3 > for the client and backend. I just moved this user's account from one > P.O. to another. The move went without a hitch, as far as I could tell; > it...

Why can't I get a User's Name?
Hi, I'm having real issues just getting the username of any user. To try to simplify it, I made my code like this and it still won't get anything. Can anyone help? <%@ Page Language="VB" %> <script runat="server"> sub page_load testing.text = User.Identity.Name end sub </script> <html> <head> </head> <body> <form runat="server"> <!-- Insert content here --> <asp:label id = "testing" runat="server"> </as...

How to update user's properties like name, mail, phone no, address, designation etc in MS Outlook
I am working on the project to prepare a user interface screen to update user property of MS Outlook. I mean, it shud allow user to update his personal info like name, designation, company, address, phone no etc. Till now, i have made the GUI screen using asp and vbscript and have been able to fetch user's properties using ado objects. Now when i try to update the properties, it is not working. The probable reason is that being stored in active directory, it cant be updated like we do in ms sql and ms access. Could you please tell me how to&...

Changing a users e-mail address without changing the user name?
I have a user that is getting a PRODIGIOUS amount of SPAM and wants their e-mail address changed. All things done in Console One: General-Identification tab: Changed e-mail address from loginname@company.com to new version firstname.lastname@company.com (which I believe is only for LDAP records?) Groupwise Tab: Internet Addressing-checked 'overide' box, selected 'firstname.lastname@company.com' --also checked 'allowed address formats'--unchecked all but 'firstname.lastname@company.com' Gateway alias--removed ALL alias (we are using an old al...

Groupwise user name in pace of first and last name
We meet a strange behaviour with groupwise client ( windows ) in caching mode. since we've chosen "caching mode", Return notification ( popup ) for tracking information display "groupwise username" in place of "first/last Name" Anyone experienced this case ? Thanks -- chabot49 ------------------------------------------------------------------------ chabot49, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been ...

multiple SMTP's and different IP's, domain names to send email from this server using different SMTP's
Is anybody can help me with this 2 issues we have: 1. We need to have multiple SMTP's installed on our server - how do you do that 2. We need to rotate different IP's, domain names to send email from this server using different SMTP's          Thanks   Third party mail server.  Look at Smartermail or iMail, Exchange if you need that much. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. Is this only option? &n...

Get user first and last name?
All  I can use the following to get my users logon name, If User.Identity.IsAuthenticated Then Label1.Text = "Welcome, <B>" + User.Identity.Name + "</B>" Label1.Text = Label1.Text & "Welcome, <B>" + Request.LogonUserIdentity.Name + "</B>" ElseResponse.Write("sorry") End If how do i now get thier first and last names thanks gibbo Plz explain  complete requirement and database Entity..?  Thanks & Regards,Murthy. I am not interacting with a database in any way, I know my us...

Member_Register.aspx
Looks like I have one last item to fix and I can publish my site.  When a new user registers, I need to ensure that the First Name, Last Name and the Address are filled in.  The template appears to have part of this logic, but it's not enforced.  I saw some old posts out there regarding this issue but didn't see a follow-up.  Does anyone know how to fix this one?  I'm using the VB version. I'm so close, but I have to have this last piece so that I can vaildate the user actually lives in our subdivision so I can assign them the proper role.  My site will be...

Extracting first name, last name, middle name from a string
I have a variable in a stored procedure that puts the first name, last name, and middle name in the format LastName, FirstName MiddleName. (I cannot just used the columns firstname, lastname, etc. as they are not available in the stored proc.) I am trying to split this up so that it reads LastName, [new line] ~r~n FirstName + MiddleName. Any suggestions on extracting this into that format? Any help greatly appreciated. I am working with Infomaker 6.0 and Windows 2000 Thanks, Sean Actually, it's just the format LastName, FirstName so I would only need to search for the comma an...

Getting A User's Real Name
Hi all. I'm working on a Intranet web app and I was wondering if I can do something. We're using Windows authentication for logging into the app. I was wondering if I can use the domain user name I have to begin with to turn around and retrieve the user's real name? Is this possible? TIA...

How to get the requeted user's name
i want to get the user's machine name who is request the web . who can help me? thanks! Try this: HttpContext.Current.Request.UserHostName --Dave http://www.loudcarrot.com/blogs/dave/...

Save e-mail address as user name
I'm using the CreateUserWizard and I would like to save the e-mail address as the user name. That means the user writes the e-mail address in the user name field. The problem is that I need to save the e-mail address which is written in the user name field also in the database so that password recovery etc. will work. How can I do that? Regards, G     Why not save the email address directly to the 2 fields (Username, Email) in the DB? You can use somthing like this to insert it into the DB.        Dim strSQL As String   &nb...

Changing user's last name
I'm running gw6 and I have a user who got married and now requested that her last name be changed. Ie. username= apple, First name= apple, Last name= turnover e-mail aturnover@abc.com She changes her lastname to lastname= pie In console one, on the users general tab I change her last name to pie as well as, the diplay name and changed the e-mail field to apie@abcd.com . Once I hit apply I get prompted with an LDAP message that it will change the e-mail. Everything is fine, User opens groupwise client after and display name is Apple Pie but the mailto or e-mail address i...

How to get current user's name ?
I want to user'name in session when DNN project is running ! How i do ? This should work for you (although i didn't test it): Dim myUserName As String = "" Dim objUser As New UsersDB() Dim dr As SqlClient.SqlDataReader = objUser.GetSingleUser(PortalId, CType(Context.User.Identity.Name, Integer)) If dr.Read Then myUserName = dr("UserName") Session("UserName") = myUserName.ToString Else Session("UserName") = "" ...

Syntax error (missing operator) in query expression 'First Name=@First Name'.
Gang,Wonder if you could help me figure out what is going on.I have the following:-   An access database with a table in it called "tblExample" -   I have the following fields within the tblExample table. (First Name, State, Zip, City)What i'm trying to do:-   I'm trying to display a text box where you type in the "First Name" of the person and it displays the City, State, and ZipThe problem:-   I get the following error message:#############################################################################################################################  Server Error in '/AppraiserDatabase' Application. Syntax error (missing operator) in query expression 'First Name=@First Name'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'First Name=@First Name'.Source Error: Line 24: objCmd.Parameters.Add("@First Name", txtSearch.Text); Line 25: objConn.Open(); Line 26: objRdr = objCmd.ExecuteReader(); Line 27: while (objRdr.Read()) Line 28: {Source File: c:\inetpub\wwwroot\Exampledatabase\WebForm1.aspx    Line: 26 Stack Trace: [OleDbException (0x80040e14): Syntax error (missing operator) in query expression 'Fir...

User's Name Changed
We are using Groupwise 5.5 I have a user that recently married. I have created a Groupwise alias for the new name, but how do I go about changing the Groupwise Object/User ID and NDS account ID and keep their email account intact? Thanks, J.Jensen Jeff, you can simply rename the Groupwise account. No mail loss. Uwe -- Novell Support Connection Volunteer SysOp Please don't send me support related e-mail unless I ask you to do so. ...

Web resources about - How to get domain user's first name, last name and e-mail address - asp.net.security

Resources last updated: 2/26/2016 4:02:02 PM