Authenticate an ASP.NET Core intranet endpoint with Windows credentials

For a Windows-domain intranet application, Negotiate authentication can identify the caller through the operating system. The application does not need to collect a password and bind to an LDAP path itself.

This example targets ASP.NET Core on Windows. A public internet application or a different identity topology usually needs a different authentication flow. It is not a mechanical replacement for every forms-authentication deployment.

Configure an authenticated endpoint

Requires .NET 10 on a domain-compatible Windows environment. Create the project and add the matching authentication package:

Plain text
dotnet new web -n WindowsAuthDemo -f net10.0
cd WindowsAuthDemo
dotnet add package Microsoft.AspNetCore.Authentication.Negotiate --version 10.0.0

Replace Program.cs:

C#
using Microsoft.AspNetCore.Authentication.Negotiate;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/whoami", (HttpContext context) => Results.Text(context.User.Identity?.Name ?? "unknown"))
	.RequireAuthorization();
app.Run();

Run the application and request /whoami through a browser/client configured to send Windows credentials to that intranet host. Expect an authentication challenge before a successful response containing the authenticated account name.

Match the hosting configuration

IIS and HTTP.sys have host-level Windows authentication settings. Configure those consistently with the application. Kestrel Negotiate deployments need the supported domain, service identity and connection behavior. Follow the host-specific documentation before placing a proxy in front of the service.

Authentication identifies a caller. It does not decide which records or actions that caller may access. Add explicit authorization policies. Windows authentication also does not automatically make every filesystem or database operation run under the caller's identity. Impersonation and delegated network access are separate decisions.

Official references

Configure Windows Authentication in ASP.NET Core
Learn how to configure Windows Authentication in ASP.NET Core for IIS and HTTP.sys.
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-10.0
Windows Authentication in ASP.NET Core

Author: Herman Schoenfeld