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.
You have to set authentication mode to Windows
in your configuration & also disable anonymous users in authorization tag.