Windows Authentication Question !!

Discussion in 'ASP .Net Security' started by naijacoder naijacoder, Oct 12, 2004.

  1. 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!





    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    naijacoder naijacoder, Oct 12, 2004
    #1
    1. Advertising

  2. naijacoder naijacoder

    Ken Schaefer Guest

    "naijacoder naijacoder" <> wrote in message
    news:...
    > 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
    Ken Schaefer, Oct 12, 2004
    #2
    1. Advertising

  3. naijacoder naijacoder

    Paul Clement Guest

    On Tue, 12 Oct 2004 04:20:44 -0700, naijacoder naijacoder <> wrote:

    ¤ 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 ~~~
    Microsoft MVP (Visual Basic)
    Paul Clement, Oct 14, 2004
    #3
  4. naijacoder naijacoder

    Chris Guest

    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



    naijacoder naijacoder <> wrote in message news:<>...
    > 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!
    >
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Chris, Oct 18, 2004
    #4
  5. 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?



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    naijacoder naijacoder, Oct 19, 2004
    #5
  6. 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.

    "naijacoder naijacoder" <> wrote in message
    news:...
    > 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?
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Joe Kaplan \(MVP - ADSI\), Oct 19, 2004
    #6
  7. naijacoder naijacoder

    Paul Clement Guest

    On Tue, 19 Oct 2004 04:10:40 -0700, naijacoder naijacoder <> wrote:

    ¤ 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 ~~~
    Microsoft MVP (Visual Basic)
    Paul Clement, Oct 19, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    667
  2. Will
    Replies:
    5
    Views:
    2,602
  3. Dadi
    Replies:
    2
    Views:
    177
    Scott Scott
    Sep 16, 2003
  4. Fabio Gouw

    ASP.NET Authentication and Windows Authentication

    Fabio Gouw, Nov 15, 2004, in forum: ASP .Net Security
    Replies:
    2
    Views:
    139
    Ken Schaefer
    Nov 16, 2004
  5. jfer
    Replies:
    3
    Views:
    545
    Dominick Baier [DevelopMentor]
    Sep 16, 2005
Loading...

Share This Page