To add windows authentication with IIS and an ASP.NET core application add this to the startup code:
builder.Services
.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
builder.Services.AddAuthorization(options =>
{
options.FallbackPolicy = options.DefaultPolicy;
});
Set windows authentication method in IIS
To get the authenticatated user use:
WindowsPrincipal winPrincipal = (WindowsPrincipal)User;
string username = winPrincipal.Identity.Name!.Split('\\').Last();
Notice, if you use WindowsIdentity.Current it returns the application pool user and not the authenticated user
Tags
ASP .NET core