We have an ASP.NET intranet site, available to users who are either physically at and logged into a local machine or else to users who connect remotely via VPN. Is there a way to automatically get the username of whoever is accessing the page based on the name used to either log into the local machine or that used for the VPN?
Asked
Active
Viewed 3.4k times
5 Answers
13
This is possible if you're using Windows Authentication in your pages.
You can use either Page.User.Identity.Name
or the more complete System.Web.HttpContext.Current.User.Identity.Name
.
Read more about it here:
Enabling Windows Authentication within an Intranet ASP.NET Web Application
If you are, however, using Forms Authentication, you'll have to keep track of the current user yourself, the most common method of which will be by storing their login name in a Session variable.

Jon Limjap
- 94,284
- 15
- 101
- 152
-
Just a note but if you use forms authentication `User.Identity.Name` will also contains the forms auth username as well. – Brent Pabst Aug 07 '12 at 16:20
3
Get the User
information as follows:
User.Identity.Name \\ Get the User name
User.Identity.AuthenticationType \\ What is the Authentication type
User.Identity.IsAuthenticated \\ Is he authenticated?
User.IsInRole("Administrators") \\ Is he administrator?

Dave Clemmer
- 3,741
- 12
- 49
- 72

Kisan Patel
- 101
- 3
3
If the authentication is setup to do Integrated Windows authentication then you should be able to get it by accessing
User.Identity.Name

David
- 19,389
- 12
- 63
- 87
1
If the authentication is windows, this should help:
IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;

Gulzar Nazim
- 51,744
- 26
- 128
- 170
-
-
Turns out the problem was that our admin had set anonymous access to true – notnot Apr 17 '09 at 19:45
-
aah i see. check out the section on anonymous access http://www.eggheadcafe.com/articles/20050703.asp – Gulzar Nazim Apr 17 '09 at 19:54