Skip to content

Commit 4a0fab0

Browse files
committed
move
1 parent d368de0 commit 4a0fab0

2 files changed

Lines changed: 35 additions & 36 deletions

File tree

aspnetcore/migration/fx-to-core/areas/includes/enable-session.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

aspnetcore/migration/fx-to-core/areas/session.md

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,44 @@ When migrating to built-in ASP.NET Core session:
117117
* You're not sharing session data with legacy applications
118118
* You want to eliminate System.Web dependencies completely
119119

120-
## Wrapped ASP.NET Core session state
120+
## System.Web Adapter Session
121121

122122
[!INCLUDE[](~/migration/fx-to-core/includes/uses-systemweb-adapters.md)]
123123

124+
### Serialization configuration
125+
126+
The <xref:System.Web.SessionState.HttpSessionState> object requires serialization for remote app session state.
127+
128+
In ASP.NET Framework, [BinaryFormatter](/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) was used to automatically serialize session value contents. In order to serialize these with for use with the System.Web adapters, the serialization must be explicitly configured using `ISessionKeySerializer` implementations.
129+
130+
Out of the box, there is a simple JSON serializer that allows each session key to be registered to a known type using `JsonSessionSerializerOptions`:
131+
132+
* `RegisterKey<T>(string)` - Registers a session key to a known type. This registration is required for correct serialization/deserialization. Missing registrations cause errors and prevent session access.
133+
134+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program.cs" id="snippet_Serialization" :::
135+
136+
If more customization is needed, then `ISessionKeySerializer` can be implemented:
137+
138+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program_Custom.cs" id="snippet_Serialization" :::
139+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program_Custom.cs" id="snippet_CustomSerializer" :::
140+
141+
> [!NOTE]
142+
> When using the `AddJsonSessionSerializer` registration pattern, there is no need to call `AddSessionSerializer` as it will automatically be added. If you only want to use a customimplementation, then you must manually add it.
143+
144+
### Enable session
145+
146+
Session support requires explicit activation. Configure it per-route or globally using ASP.NET Core metadata:
147+
148+
* Annotate controllers
149+
150+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/remote/SomeController.cs" id="snippet_Controller" :::
151+
152+
* Enable globally for all endpoints
153+
154+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/remote/Program.cs" id="snippet_RequireSystemWebAdapterSession" :::
155+
156+
## Wrapped ASP.NET Core session state
157+
124158
Choose this approach when your migrated components don't need to share session data with your legacy application.
125159

126160
The `Microsoft.Extensions.DependencyInjection.WrappedSessionExtensions.AddWrappedAspNetCoreSession` extension method adds a wraps ASP.NET Core session to work with the adapters. It uses the same backing store as <xref:Microsoft.AspNetCore.Http.ISession> while providing strongly-typed access.
@@ -133,8 +167,6 @@ Your Framework application requires no changes.
133167

134168
For more information, see the [wrapped session state sample app](https://github.com/dotnet/systemweb-adapters/blob/main/samples/SessionLocal/SessionLocalCore/Program.cs)
135169

136-
[!INCLUDE[](~/migration/fx-to-core/areas/includes/enable-session.md)]
137-
138170
## Remote app session state
139171

140172
[!INCLUDE[](~/migration/fx-to-core/includes/uses-systemweb-adapters.md)]
@@ -147,26 +179,6 @@ Remote app session enables communication between applications to retrieve and se
147179

148180
Complete the [remote app setup](xref:migration/fx-to-core/inc/remote-app-setup) instructions to connect your ASP.NET Core and ASP.NET Framework applications.
149181

150-
### Serialization configuration
151-
152-
The <xref:System.Web.SessionState.HttpSessionState> object requires serialization for remote app session state.
153-
154-
In ASP.NET Framework, [BinaryFormatter](/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) was used to automatically serialize session value contents. In order to serialize these with for use with the System.Web adapters, the serialization must be explicitly configured using `ISessionKeySerializer` implementations.
155-
156-
Out of the box, there is a simple JSON serializer that allows each session key to be registered to a known type using `JsonSessionSerializerOptions`:
157-
158-
* `RegisterKey<T>(string)` - Registers a session key to a known type. This registration is required for correct serialization/deserialization. Missing registrations cause errors and prevent session access.
159-
160-
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program.cs" id="snippet_Serialization" :::
161-
162-
If more customization is needed, then `ISessionKeySerializer` can be implemented:
163-
164-
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program_Custom.cs" id="snippet_Serialization" :::
165-
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/serialization/Program_Custom.cs" id="snippet_CustomSerializer" :::
166-
167-
> [!NOTE]
168-
> When using the `AddJsonSessionSerializer` registration pattern, there is no need to call `AddSessionSerializer` as it will automatically be added. If you only want to use a customimplementation, then you must manually add it.
169-
170182
### Application configuration
171183

172184
:::zone pivot="manual"
@@ -200,8 +212,6 @@ var coreApp = builder.AddProject<Projects.CoreApplication>("core")
200212

201213
:::zone-end
202214

203-
[!INCLUDE[](~/migration/fx-to-core/areas/includes/enable-session.md)]
204-
205215
### Communication protocol
206216

207217
#### Readonly sessions

0 commit comments

Comments
 (0)