Windows Authentication Question !!

  • Thread starter naijacoder naijacoder
  • Start date
N

naijacoder naijacoder

Hi Guys,
I have <%=User.Identity.Name%> on my asp.net page and i can
retrieve the Username for example ComputerName/Username or
DomainName/Username.
But my Question is how can i retrieve the full username for
example "John Brown" or the DisplayName.
Any help from you guys!
 
K

Ken Schaefer

naijacoder naijacoder said:
Hi Guys,
I have <%=User.Identity.Name%> on my asp.net page and i can
retrieve the Username for example ComputerName/Username or
DomainName/Username.
But my Question is how can i retrieve the full username for
example "John Brown" or the DisplayName.
Any help from you guys!

You have to find out where the "DisplayName" is supposed to be coming from.
When a user authenticates from their web-browser, it only passes the
username and password (or hash/digest of password), not any of the other
properties that might be stored in Active Directory (AD), or in the local
machine's Security Accounts Manager (SAM) Database. If the information is
stored in AD, you would need to use some code to query AD to get the
properties that you want.

Lots of good info:
http://www.google.com.au/search?q=query+active+directory+using+ASP.NET

Cheers
Ken
 
P

Paul Clement

¤ Hi Guys,
¤ I have <%=User.Identity.Name%> on my asp.net page and i can
¤ retrieve the Username for example ComputerName/Username or
¤ DomainName/Username.
¤ But my Question is how can i retrieve the full username for
¤ example "John Brown" or the DisplayName.
¤ Any help from you guys!
¤

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
Dim FullName As String = ADEntry.Properties("FullName").Value


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
C

Chris

Here ya go.

<%
'get the userName from the form
dim userName as String

userName = Request.Form("userName")

dim con, Com, rs, fullName, description

con = Server.CreateObject("ADODB.Connection")
con.provider = "ADsDSOObject"
con.open("Active Directory Provider")

Com = CreateObject("ADODB.Command")
Com.ActiveConnection = con

Com.CommandText = "SELECT displayName, description, cn FROM
'LDAP://DOMAIN NAME/CN=" & userName & ",OU=GROUP NAME' WHERE
sAMAccountname = '" & userName & "'"
rs = Com.Execute

if not rs.bof and not rs.eof then
fullName = rs("displayName").value
description = rs("cn").value
end if
%>

***** MAKE SURE TO CHANGE THE DOMAIN NAME AND GROUP NAME IN THE LDAP
SELECT STATEMENT. ALSO, YOU WILL NEED TO HAVE AN "OU=" FOR EVERY
GROUP IN YOUR AD HIERARCHY.

Chris
 
N

naijacoder naijacoder

Thx for the code..
But the thing is that i need to display THE USER LOGGED ON(ON TOP OF MY
ASP.PAGE)(BUT THE DISPLAY NAME).
I don't want to display LIST of NAMES!
Any ideas?
 
J

Joe Kaplan \(MVP - ADSI\)

You could use System.DirectoryServices fairly easily to search for the user
by their samAccountName and get their displayName from AD.

The samAccountName is the part to the right of the \ in the user name you
get from Context.User.Identity.Name.

There are tons of samples out there that show how to use the
DirectorySearcher.

Joe K.
 
P

Paul Clement

¤ Thx for the code..
¤ But the thing is that i need to display THE USER LOGGED ON(ON TOP OF MY
¤ ASP.PAGE)(BUT THE DISPLAY NAME).
¤ I don't want to display LIST of NAMES!
¤ Any ideas?

I have no idea what you are referring to. The FullName, using the NT provider, is the same as the
displayName using the LDAP provider.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top