How to get the username of the user accessing ASP.NET intranet page within local network?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

If the authentication is setup to do Integrated Windows authentication then you should be able to get it by accessing

User.Identity.Name

Method 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?

Method 4

If the authentication is windows, this should help:

IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;

Method 5

You can use

Page.User.Identity.Name


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x