Skip to content

Commit 61a3eba

Browse files
Copilotwadepickett
andauthored
Fix Windows Authentication Kestrel documentation to highlight UseAuthentication middleware (#36230)
* Initial plan * Fix Windows Authentication Kestrel section to highlight UseAuthentication middleware Co-authored-by: wadepickett <[email protected]> * Apply suggestion from @wadepickett Fixed a misleading sentence. Kestral does not natively implement Windows Authentication, the NuGet package enables it. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wadepickett <[email protected]> Co-authored-by: Wade Pickett <[email protected]>
1 parent c6d5fe5 commit 61a3eba

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

aspnetcore/security/authentication/windowsauth.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure Windows Authentication in ASP.NET Core for I
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 08/10/2025
8+
ms.date: 10/17/2025
99
uid: security/authentication/windowsauth
1010
ms.ai: assisted
1111
---
@@ -168,23 +168,29 @@ Use **either** of the following approaches:
168168

169169
## Kestrel
170170

171-
The [`Microsoft.AspNetCore.Authentication.Negotiate` NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Negotiate) can be used with [Kestrel](xref:fundamentals/servers/kestrel) to support Windows Authentication using Negotiate and Kerberos on Windows, Linux, and macOS.
171+
The [`Microsoft.AspNetCore.Authentication.Negotiate` NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Negotiate) can be used with [Kestrel](xref:fundamentals/servers/kestrel) to enable Windows Authentication using Negotiate and Kerberos on Windows, Linux, and macOS.
172172

173173
> [!WARNING]
174174
> Credentials can be persisted across requests on a connection. *Negotiate authentication must not be used with proxies unless the proxy maintains a 1:1 connection affinity (a persistent connection) with Kestrel.*
175175
176176
> [!NOTE]
177177
> The Negotiate handler detects if the underlying server supports Windows Authentication natively and if it is enabled. If the server supports Windows Authentication but it is disabled, an error is thrown asking you to enable the server implementation. When Windows Authentication is enabled in the server, the Negotiate handler transparently forwards authentication requests to it.
178178
179-
Authentication is enabled by the following highlighted code to `Program.cs`:
179+
Authentication and a fallback authorization policy are enabled by the following highlighted code in `Program.cs`:
180+
181+
[!code-csharp[](windowsauth/6.0samples/WebRPwinAuth/Program.cs?name=snippet1&highlight=1,5-6,8-11,26-27)]
180182

181-
[!code-csharp[](windowsauth/6.0samples/WebRPwinAuth/Program.cs?name=snippet1&highlight=1,4-11,27-28)]
183+
The preceding code was generated by the ASP.NET Core Razor Pages template with **Windows Authentication** specified.
182184

183-
The preceding code was generated by the ASP.NET Core Razor Pages template with **Windows Authentication** specified. The following APIs are used in the preceding code:
185+
Highlighted lines:
184186

185-
* <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication%2A>
186-
* <xref:Microsoft.Extensions.DependencyInjection.NegotiateExtensions.AddNegotiate%2A>
187-
* <xref:Microsoft.AspNetCore.Builder.AuthAppBuilderExtensions.UseAuthentication%2A>
187+
* 5–6: <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication%2A> and <xref:Microsoft.Extensions.DependencyInjection.NegotiateExtensions.AddNegotiate%2A> register and configure the Negotiate authentication handler.
188+
* 8–11: <xref:Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions.AddAuthorization%2A> with a fallback policy enforces authenticated users by default.
189+
* 26: <xref:Microsoft.AspNetCore.Builder.AuthAppBuilderExtensions.UseAuthentication%2A> executes authentication handlers for each request and populates <xref:Microsoft.AspNetCore.Http.HttpContext.User?displayProperty=nameWithType>.
190+
* 27: <xref:Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization%2A> evaluates authorization policies, including the fallback policy.
191+
192+
> [!NOTE]
193+
> Calling <xref:Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication%2A> and <xref:Microsoft.Extensions.DependencyInjection.NegotiateExtensions.AddNegotiate%2A> registers and configures the Negotiate handler; it does not run authentication per request. The Authentication middleware (<xref:Microsoft.AspNetCore.Builder.AuthAppBuilderExtensions.UseAuthentication%2A>) invokes the handler and populates <xref:Microsoft.AspNetCore.Http.HttpContext.User?displayProperty=nameWithType>, and must appear before <xref:Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization%2A> for policy evaluation to work.
188194
189195
<a name="rbac"></a>
190196
### Kerberos authentication and role-based access control (RBAC)

0 commit comments

Comments
 (0)