Get Full Display Name from Windows Logon in .Net

I've tried many variations, but based on the following code snippet do you see how I could get the full users display name from the windows logon?  I have NO experience with .NET.  My attempts have been via standard vb script without success:

      Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
          Integer.TryParse(Request.QueryString("forumid"), RequestedForumID)
               If Not User.Identity.IsAuthenticated Then

                Dim strUsrNm As String    
               
               'Build a string containing the AD account name of the Windows Authenticated user         
                strUsrNm = Request.ServerVariables("LOGON_USER")
                  strUsrNm = Mid$(strUsrNm, InStr(1, strUsrNm, "\") + 1)

               'Create the authentication ticket and add it to the cookie collection
                FormsAuthentication.SetAuthCookie(strUsrNm, False)
               'refresh the current page so the it displays Welcome <username>
                Response.Redirect(Me.Request.Url.ToString)
            End If
      End Sub
TCCIRMAsked:
Who is Participating?
 
guru_samiCommented:
Basicall you will use classes in  System.DirectoryServices namespace.

See if these helps:

http://www.wwwcoder.com/main/parentid/272/site/1694/68/default.aspx
Step 16: http://www.vbdotnetheaven.com/UploadFile/ecabral/ADandNETInVB11112005020216AM/ADandNETInVB.aspx

You will need to set LDAP string accordingly.
0
 
guru_samiCommented:
So are you using FormsAuthentication  or Windows?
You can check that in your web.config file.
Also can you explain with example what you mean with full display name
0
 
TCCIRMAuthor Commented:
I will be using Windows authentication.  Right now the current code retrieves the Windows logon name and I want to get the full diplay name.  I've been able to get the full display name from Active Directory in other apps via classic asp like below but have been unable to entirely adapt it to .net.  Above is a code snippet from a .net app I am trying to modify.

     Dim strLogonUser
     Dim strDomain
     Dim strLogonName
   
     strLogonUser = Request.ServerVariables("Logon_User")
     strDomain = Mid(strLogonUser, 1, Instr(1, strLogonUser, "\") - 1)
     strLogonName = Mid(strLogonUser, Instr(1, strLogonUser, "\") + 1)

    Set dUser = GetObject("WinNT://" & strDomain & "/" & strLogonName & "")
    Display = dUser.Fullname
 
     Function GetUserFullName(strDomainName, strLogonName)
    End Function
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
TCCIRMAuthor Commented:
Sorry for the delayed response but after much toil, it is apparent I do not have permissions to access our networks LDAP server thus I am unable to utilize this method.  Any other recommendations how I might retrieve the users full display name?  Thanks
0
 
TCCIRMAuthor Commented:
I guess my request is not possible.  Thanks anyway....
0
 
guru_samiCommented:
Sorry I missed your previous response. It is not that only your account should have access but you can ask your IT or AD Admin to give you appropriate connectionstring to LDAP.
I am not sure there is any other way for getting user details without querying LDAP.
0
 
TCCIRMAuthor Commented:

Unfortunately I am at the bottom of the food chain and will not be given access to LDAP.  I appreciate the initial response.  The points are yours.  I'll give this one a rest and possibly revisit it another time.  Thanks  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.