I have an ASP.NET 3.5 application that uses ASP.NET forms authentication. I want to be able to get the Windows user name currently logged into the computer (NOT logged into the ASP.NET application, but into Windows) when data is edited in a page.
If I use Context.User.Identity.Name.Tostring()
, I get the user name logged into the ASP.NET application, but I need the Windows account name.
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()
Also, it only works when I run the website from Visual Studio, but after deploying to IIS it returns NT AUTHORITY\SYSTEM.
GetCurrent(). Name; Returns: NetworkName\Username. Gets the user's Windows logon name.
Click on "Task Manager." 4. In the new menu, select the "Users" tab. Your username will be listed here.
Type whoami and press Enter. Your current user name will be displayed.
Techopedia Explains User Identification (User ID)Typically in an authentication process, user ID is used in conjunction with a password. The end-user must provide both of the credentials correctly to gain access to the system or application.
You have to set authentication mode to Windows
in your configuration & also disable anonymous users in authorization tag.
To get the currently logged in user to a Windows account you have to use Windows authentication
instead of Forms authentication
:
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring() also only works when i run the website from visual studio but after deploying to IIS it returns NT AUTHORITY\SYSTEM
It shows the application current user. When you host your application on the Visual Studio web server it uses your local account. However, when you will log in to the web application with different credentials it will always show your current Windows login.
An application deployed to IIS uses the NT AUTHORITY\SYSTEM account in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With