How to get Windows loggedin username in IIS defind anonymous + windows authentication

911 Views Asked by At

framework : ASP.NET CORE 2.2 as web-api Server: IIS-10 (Windows server 2016)

I need to work with both WindowsAuthentication and AnonymousAuthentication. I have these 2 options to somehow get the Windows LoggedIn User:

User.Identity.Name; 

System.Security.Principal.WindowsIdentity.GetCurrent().Name 

I use them in an end-point (controller method) which is reached anonymous.

Everything works fine with IISExpress, but when working with IIS (local or after deploy), I can't get the wanted results:

User.Identity.Name; // return null

System.Security.Principal.WindowsIdentity.GetCurrent().Name //return IISAPPPOOL\<Application pool name>

Application Pool Identity is ApplicationPoolIdentity.

How can I get the Windows LoggedIn Username in this configuration (anonymous + windows authentication)?

0

There are 0 best solutions below