Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out what user my ASP.Net MVC application is running as?

I want to display the windows user that the application is running as on a diagnostics page on my ASP.Net MVC database check page to help the user check whether they've setup their IIS correctly. Where can I find that information?

I tried System.Threading.Thread.CurrentPrincipal.Identity.Name but that appears to contain the logged in user by forms authentication, not the underlying windows user that the code is running as.

like image 767
Colin Newell Avatar asked Dec 30 '22 03:12

Colin Newell


2 Answers

WindowsIdentity.GetCurrent().Name
like image 200
Keith Adler Avatar answered Feb 01 '23 13:02

Keith Adler


You can use System.Environment.UserName to get the windows user account that the application is running as.

like image 29
womp Avatar answered Feb 01 '23 14:02

womp