Once I know the machine name, can I get the Windows username?
There is no necessary connection between the two.
You can try using
Environment.UserName (If you test Environment.UserName using RunAs, it will give you the RunAs user account name, not the user originally logged on to Windows.)
String UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name (returns DomainName\UserName);
set authentication mode to
Windows in your configuration & also disable anonymous users in authorization tag.
<configuration> <system.web> <authentication mode="Windows" /> <authorization> <deny users="?"/> </authorization> </system.web> </configuration>
var userId = this.User.Identity.Name;
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.