Get the local system's user name

807 Views Asked by At

In my web application, I need to display the username who is currently logged in the system. Am having a Text-box and a Button in my form. Example : If the user "Admin" is currently logged in and using the (Local)system. Once I clicked the button the name Admin has to be displayed in the Text-box.

2

There are 2 best solutions below

0
On BEST ANSWER

Please try below code for getting current username

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
0
On

Hey Please refer this code for Asp.Net

string currentUsername = System.Web.HttpContext.Current.User.Identity.Name;

This is tested code.