0

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)?

Guy E
  • 1,775
  • 2
  • 27
  • 55
  • 1
    "I need to work with both WindowsAuthentication and AnonymousAuthentication." I think you don't know what you are asking for. Enabling anonymous authentication on IIS automatically prevents all other methods (like Windows authentication) from working. Forget about IIS Express, because it is not IIS, https://blog.lextudio.com/web-application-differences-in-visual-studio-and-iis-60fec7e311b3 – Lex Li Sep 22 '21 at 14:58
  • If you enable both Windows Authentication and anonymous authentication at the same time, then only anonymous authentication will be enabled, if you want to get Windows Log Username, you need to disable anonymous authentication. and this link should help you: [https://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net](https://richhewlett.com/2011/02/15/getting-a-users-username-in-asp-net). – samwu Sep 23 '21 at 03:17
  • But Microsoft tell is possible use WindowsAuthentication and AnonymoutsAuthentication enabled on the same time: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-5.0&tabs=visual-studio#allow-anonymous-access-1 – Marco Dec 07 '21 at 09:41
  • Has Windows Authentication be installed in IIS Server? Having it enabled on the project side is not sufficient. – taylorswiftfan Nov 04 '22 at 00:26

0 Answers0