Get the name of the user accessing the ASP.NET intranet page on the local network

We have an ASP.NET intranet site available for users who are physically connected to or logged into the local machine, as well as for users who connect remotely via a VPN. Is there a way to automatically get the username of the person who accesses the page based on the name used to log in to the local computer or for use in the VPN?

+4
source share
5 answers

This is possible if you use Windows authentication on your pages.

You can use either Page.User.Identity.Name or the more complete System.Web.HttpContext.Current.User.Identity.Name .

Read more about this here:

Enabling Windows Authentication in an ASP.NET Intranet Web Application

If you, however, use forms authentication, you will need to track the current user yourself, the most common method is to save their login in a session variable.

+13
source

Get 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? 
+3
source

If authentication is configured for integrated Windows authentication, you should obtain it by contacting

 User.Identity.Name 
+2
source

you can use

 Page.User.Identity.Name 
+1
source

If authentication is windows, this should help:

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

All Articles