getting username logged in

B

Brian Henry

im wokring on an intranet site, and i need the username of the current user
logged in so it displays their information, how do i find out the user name
thats logged into the system so i can use it in asp.net?
 
J

John Saunders

Francis Shanahan said:
I assume you've authenticated with Forms authentication, if not just replace
Forms in this example with Generic.

If Not (HttpContext.Current.User Is Nothing) Then
If (HttpContext.Current.User.Identity.IsAuthenticated) Then
If (TypeOf HttpContext.Current.User.Identity Is
FormsIdentity) Then
Dim userIdentity As FormsIdentity =
CType(HttpContext.Current.User.Identity, FormsIdentity)

/////////Once you have the userIdentity you can get the username I think.
End If
End If
End If

End Sub

Actually, the following will work:

Dim UserName As String = Nothing
If Not (HttpContext.Current.User Is Nothing) AndAlso _
(HttpContext.Current.User.Identity.IsAuthenticated) Then
UserName = HttpContext.Current.User.Identity.Name
End If

If you place this code on a web form or user control, you can simply refer
to "Context" instead of "HttpContext.Current", and you can use
Request.IsAuthenticated.
 
B

Brian Henry

Thanks! I had a problem at first, but turned out I forgot to turn on windows
authentication and turn off anonymous access in IIS... your code worked
great!
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top