You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/migration/fx-to-core/areas/authentication.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,11 @@
1
1
---
2
2
title: ASP.NET Framework to Core Authentication Migration
3
+
ai-usage: ai-assisted
4
+
author: twsouthwick
3
5
description: ASP.NET Framework to Core Authentication Migration
4
-
author: wadepickett
5
-
ms.author: wpickett
6
6
monikerRange: '>= aspnetcore-6.0'
7
-
ms.date: 09/24/2025
7
+
ms.author: tasou
8
+
ms.date: 12/10/2025
8
9
ms.topic: article
9
10
uid: migration/fx-to-core/areas/authentication
10
11
zone_pivot_groups: migration-remote-app-setup
@@ -216,6 +217,15 @@ var coreApp = builder.AddProject<Projects.AuthRemoteIdentityCore>("core")
216
217
Once this is done, it will be automatically hooked up in both the framework and core applications.
217
218
:::zone-end
218
219
220
+
#### Remote authentication with YARP fallback
221
+
222
+
When using remote authentication with YARP-based fallback to the ASP.NET Framework app, make sure that fallback requests don't invoke remote authentication. If remote authentication runs during fallback, the app makes unnecessary extra calls back to the Framework app and can lead to confusing behavior.
223
+
224
+
To avoid running remote authentication for fallback requests, use one of these approaches:
225
+
226
+
* Use routing short-circuit metadata on the YARP fallback route so that the route bypasses the rest of the middleware pipeline. For example, call `ShortCircuit` on the fallback endpoint as shown in the remote app setup guidance and in [Short-circuit middleware after routing](xref:fundamentals/routing#short-circuit-middleware-after-routing).
227
+
* Don't use remote authentication as the default authentication scheme. Instead, configure remote authentication only for the endpoints that need it. For example, pass `false` to `AddAuthenticationClient` and specify the remote authentication scheme explicitly on those endpoints.
228
+
219
229
#### Using Remote Authentication with Specific Endpoints
220
230
221
231
When you set the default scheme to `false`, you can specify remote authentication for specific controllers or actions:
@@ -340,7 +350,7 @@ Note that because signing in typically depends on a specific database, not all a
340
350
* Both apps are able to see the users' identity and claims.
341
351
* Both apps are able to sign the user out.
342
352
343
-
Details on how to configure sharing auth cookies between ASP.NET and ASP.NET Core apps are available in [cookie sharing documentation](xref:security/cookie-sharing). For more information about cookie authentication in ASP.NET Core, see <xref:security/authentication/cookie>.
353
+
Details on how to configure sharing auth cookies between ASP.NET and ASP.NET Core apps are available in [cookie sharing documentation](xref:security/cookie-sharing). For more information about cookie authentication in ASP.NET Core, see <xref:security/authentication/cookie>. For guidance on configuring `<machineKey>` and data protection when sharing protected values between Framework and Core apps, see <xref:migration/fx-to-core/areas/machine-key>.
344
354
345
355
The following samples in the [System.Web adapters](https://github.com/dotnet/systemweb-adapters) GitHub repo demonstrates remote app authentication with shared cookie configuration enabling both apps to sign users in and out:
Copy file name to clipboardExpand all lines: aspnetcore/migration/fx-to-core/areas/hosting.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ai-usage: ai-assisted
5
5
author: twsouthwick
6
6
ms.author: tasou
7
7
monikerRange: '>= aspnetcore-6.0'
8
-
ms.date: 11/10/2025
8
+
ms.date: 12/10/2025
9
9
ms.topic: article
10
10
uid: migration/fx-to-core/areas/hosting
11
11
---
@@ -61,9 +61,6 @@ The `HttpApplicationHost.RegisterHost` method configures a generic host that run
61
61
62
62
## Dependency injection
63
63
64
-
> [!NOTE]
65
-
> This currently is in a preview version of the adapters. You must be using 2.2.0-preview1.25554.5 or greater to use this feature.
66
-
67
64
The `AddSystemWebDependencyInjection` method enables dependency injection throughout your ASP.NET Framework application. Services registered with the generic host's service collection become available to controllers, handlers, and other components.
68
65
69
66
This extension method is an internal method that will be source generated depending on what you have referenced. The following frameworks are supported:
@@ -72,6 +69,9 @@ This extension method is an internal method that will be source generated depend
72
69
- ASP.NET MVC using <xref:System.Web.Mvc.DependencyResolver>
73
70
- ASP.NET WebApi using [DependencyResolver](/previous-versions/aspnet/hh969140(v=vs.108))
74
71
72
+
> [!NOTE]
73
+
> The `builder.AddSystemWebDependencyInjection()` extension method is generated by a C# source generator and is only available in C# projects. For VB.NET apps, create an intermediate C# class library that references the ASP.NET MVC/Web API and SystemWebAdapters packages. Configure dependency injection in that library and expose a public method that your VB.NET project can call.
74
+
75
75
### Registering services
76
76
77
77
Register services with the dependency injection container by accessing the `Services` property on the host builder:
In the ASP.NET Framework app, configure `<machineKey>` and the System.Web adapters host so that both apps can share a compatible data protection configuration. For full background on replacing `<machineKey>`, see <xref:security/data-protection/compatibility/replacing-machinekey>.
18
+
19
+
This guidance builds on the `System.Web` adapters hosting model so that data protection services are registered in the host dependency injection (DI) container and made available throughout the ASP.NET Framework app. By integrating with the host DI provided by the adapters, existing ASP.NET Framework components can resolve `IDataProtectionProvider`, `IDataProtector`, and related types.
20
+
21
+
Both the ASP.NET Framework app and the ASP.NET Core app must use a shared application name and key repository for data protection so that protected payloads can round-trip between apps.
22
+
23
+
* Call `SetApplicationName` with the same logical application name in both apps (for example, `"my-app"`).
24
+
* Configure `PersistKeysToFileSystem` to point to the same key repository location that both apps can read and write.
25
+
26
+
> [!NOTE]
27
+
> The directory used with `PersistKeysToFileSystem` is the backing store for the shared data protection keys. In production, use a durable, shared store (such as a UNC share, Redis, or Azure Blob Storage) and follow the key management guidance in <xref:security/data-protection/configuration/overview> and <xref:security/data-protection/introduction>.
28
+
29
+
## Configure the ASP.NET Framework app
30
+
31
+
To implement this configuration in the ASP.NET Framework app, ensure the `Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices` package is installed in the ASP.NET Framework app.
32
+
33
+
When you install the `Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices` package in the ASP.NET Framework app, it normally configures `<machineKey>` automatically. If `<machineKey>` isn't present or you need to verify the settings, configure `` in *Web.config* to use the compatibility data protector as shown:
Next, in `Global.asax.cs`, register the System.Web adapters host and configure data protection using the same application name and key repository that the ASP.NET Core app will use. The following example is adapted from the MachineKey Framework sample:
* Sets a shared application name (`my-app`) that the ASP.NET Core app must also use.
79
+
* Configures a shared key repository (for example, a UNC share) that both apps can access.
80
+
* Ensures `<machineKey>` operations (forms auth, view state, `MachineKey.Protect`, and related APIs) are routed through ASP.NET Core data protection.
81
+
* Runs as part of the ASP.NET Framework host so that existing `<machineKey>`-based features use the same data protection system as ASP.NET Core.
82
+
83
+
## Configure the ASP.NET Core app
84
+
85
+
No additional configuration is required for data protection in the ASP.NET Core app. Just configure the same application name and key storage location that the ASP.NET Framework app uses.
>ThisintegrationiscurrentlyinpreviewandispublishedasaprereleasepackageonNuGet.org. Whenaddingthepackage, enableprereleasepackagesinyourtooling (forexample, select `Includeprerelease` inVisualStudio's NuGet Package Manager or use the equivalent prerelease option with the .NET CLI).
0 commit comments