473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

getting username logged in

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?
Nov 17 '05 #1
2 2341
"Francis Shanahan" <fs@NoSpamTodayThanks.francisshanahan.com> wrote in
message news:O7**************@tk2msftngp13.phx.gbl...
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.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #2
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!
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Francis Shanahan" <fs@NoSpamTodayThanks.francisshanahan.com> wrote in
message news:O7**************@tk2msftngp13.phx.gbl...
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.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DMc2004 | last post by:
I have serveral items I would to find out how to do: 1) How to get the username of the person currently logged onto a workstation; 2) How to get the username of who is logged onto a different...
8
by: Jonathan Dixon | last post by:
I am developing an intranet and was wondering, when a user logs on is there a way to get the username of the windows account in asp.net. I have tried the following but they return the worker...
6
by: John Dalberg | last post by:
I want to automate the process of logging into an intranet. I want to pull out the username of the Windows user logged into the machine running the browser and use the username in my app. How can I...
11
by: Derek Martin | last post by:
Using VB.Net, I would like to retrieve the currently logged in user's DN from Active Directory. Alternatively, if, using WindowsIdentity, or something similar, I would like to get the user's full...
2
by: Scott M. Lyon | last post by:
I'm having some strange problems with a VB.NET application that I support. The application currently uses SystemInformation.UserName() and SystemInformation.UserDomainName() to determine who is...
1
by: jodyblau | last post by:
I applogize for posting this a second time (I posted in the access-multiuser group as well), but this group seems to respond more rapidly, and I have been trying to figure this out for what seems...
1
by: eswanson | last post by:
How do you get the currently logged in user from a regular c sharp class? I have a common utility class in which I have some static functions that called from multiple places. In one of the...
1
by: rahulya007 | last post by:
Hi, I am trying to implement single sign-on like feature in my website (running on IIS and ASP). A windows Authenticated logged in user will be directed to a welcome screen directly without asking...
8
by: simonlpwaters | last post by:
I need to obtain the username of the currently logged in user on a machine. However, the program that needs to do this will be running under different credentials to the logged in user, so using...
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.