Skip to content

Commit ccb597e

Browse files
authored
Add a migration scenario for Blazor (#34011)
1 parent b259981 commit ccb597e

File tree

1 file changed

+37
-1
lines changed
  • aspnetcore/migration/80-to-90/includes

1 file changed

+37
-1
lines changed
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
Blazor migration guidance will appear here prior to the release of .NET 9, which is scheduled for November, 2024.
1+
### Adopt simplified authentication state serialization for Blazor Web Apps
2+
3+
Blazor Web Apps can optionally adopt [simplified authentication state serialization](xref:aspnetcore-9#simplified-authentication-state-serialization-for-blazor-web-apps).
4+
5+
In the server project:
6+
7+
* Remove the Persisting Authentication State Provider (`PersistingAuthenticationStateProvider.cs`).
8+
9+
* Remove the service registration from the `Program` file. Instead, chain a call to <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyRazorComponentsBuilderExtensions.AddAuthenticationStateSerialization%2A> on <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A>:
10+
11+
```diff
12+
- builder.Services.AddScoped<AuthenticationStateProvider, PersistingAuthenticationStateProvider>();
13+
14+
builder.Services.AddRazorComponents()
15+
.AddInteractiveServerComponents()
16+
.AddInteractiveWebAssemblyComponents()
17+
+ .AddAuthenticationStateSerialization();
18+
```
19+
20+
The API only serializes the server-side name and role claims for access in the browser. To include all claims, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializationOptions.SerializeAllClaims> to `true`:
21+
22+
```csharp
23+
.AddAuthenticationStateSerialization(options => options.SerializeAllClaims = true);
24+
```
25+
26+
In the client project (`.Client`):
27+
28+
* Remove the Persistent Authentication State Provider (`PersistentAuthenticationStateProvider.cs`).
29+
30+
* Remove the service registration from the `Program` file. Instead, call <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyAuthenticationServiceCollectionExtensions.AddAuthenticationStateDeserialization%2A> on the service collection:
31+
32+
```diff
33+
- builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>();
34+
+ builder.Services.AddAuthenticationStateDeserialization();
35+
```
36+
37+
For more information, see <xref:aspnetcore-9#simplified-authentication-state-serialization-for-blazor-web-apps>.

0 commit comments

Comments
 (0)