Solved

User's login name not appearing on intranet ASP.net page

Posted on 2011-03-03
4
729 Views
Last Modified: 2012-08-13
I am new to ASP.net and am learning and writing a web site application in VS 2010 that will eventually become our company's intranet web site.  As part of the start page, I want to display the user's name in a welcome message like:  "Welcome:  E Young".

The company's intranet is being hosted on a new, virtual file server that is running Windows 2008 R2.  I installed IIS 7.5 and have attempted to configure it but I am new to IIS 7.5 also.  The users will access the company's intranet via IE 8 using the url for our intranet site.  I am developing the ASP.net web site using VS 2010 on my development computer then transferring the files from my computer to the new intranet computer's C:\Inetpub\wwwroot\ folder.

That all seems to be working fine except for the Welcome message.  When I start IE 8 on my development computer or the intranet server and type in the web site url, I do see the starting page that I have developed but the Welcome message does not show the user's name.  It just shows "Welcome:".  However, when I run the web site from my development computer from within VS 2010, I do see the welcome message, i.e. "Welcome:  E Young" correctly.

IE 8 does have windows authentication enabled as does IIS 7.5 yet the web site is not able to pickup the user's windows login name and display it.

Below is the code from the Default.aspx.vb file along with the Default.aspx file showing the displaying of the Welcome message.

This question was previously posted but although many things were tried, no answer was found.  Here is the previous question:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_26859204.html#a35032237

Thank you for the help.
Here is the Default.aspx.vb code:

Imports System.DirectoryServices.AccountManagement

Partial Class _Default
    Inherits System.Web.UI.Page
    'Inherits UserPrincipal

    Public mUserName As String
    Public mWelcomeMessage As String
    Public mInt As Integer
    Public mUser_Initial As String
    Public mUser_Last_Name As String

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            'mUserName = UserPrincipal.Current.DisplayName
            mUserName = Trim(System.Web.HttpContext.Current.User.Identity.Name)
            If mUserName > "" Then
                mInt = InStr(mUserName, "\")
                If mInt > 0 Then
                    mUserName = Mid(mUserName, mInt + 1, Len(mUserName) - (mInt))
                    mUser_Initial = UCase(Left(mUserName, 1))
                    mUser_Last_Name = UCase(Mid(mUserName, 2, 1)) & Mid(mUserName, 3, Len(mUserName) - 2)
                    mWelcomeMessage = "Welcome:  " & mUser_Initial & " " & mUser_Last_Name
                Else
                    mWelcomeMessage = "Welcome:  " & mUserName
                End If
            Else
                mWelcomeMessage = ""
            End If
        Catch
            If Err.Number <> 0 Then
                mUserName = ""
            End If
        End Try
    End Sub
End Class

===========================================================================

Here is the Default.aspx code showing the displaying of the mWelcomeMessage on the ASP page:
    ...
    <form runat="server">       
        
        <div style="position:absolute; top:115px; left:825px; z-index: 1; visibility:visible; height: 20px; width: 300px; text-align:right;">
            <p><%= mWelcomeMessage%></p>
        </div>        
        ...

Open in new window

0
Comment
Question by:EYoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
Tray896 earned 500 total points
ID: 35058350
I know you said that Windows Authentication is enabled in IIS, but have you confirmed that Anonymous is disabled?  If both Anonymous and Windows Auth are enabled, it will first attempt to authenticate via anonymous.  If Anonymous is enabled that would explain why it is not picking up the username.
0
 
LVL 7

Author Comment

by:EYoung
ID: 35058543
Anonymous Authentication is Disabled.  I think that Windows Authentication is Enabled as I ran a command line utility that was suppose to start it but it does not show up in the Authentication window in IIS 7.5.  I would have thought it would show up.  How do I confirm that Windows Auth. is Enabled?

0
 
LVL 7

Author Closing Comment

by:EYoung
ID: 35058820
Thank you for the help and guidance.
0
 
LVL 7

Author Comment

by:EYoung
ID: 35058828
Success.  The command line program does not work but following these directions does enable Windows Authentication, does cause Windows Authentication to appear in the IIS authentication window, and does now display the user's login name to appear.  Finally.

See:  http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication

Thank you for all the help.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question