Skip to content

Commit c1f9415

Browse files
committed
update sesison
1 parent 3b576a4 commit c1f9415

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,6 @@ The [System.Web adapters](~/migration/fx-to-core/inc/systemweb-adapters.md) enab
7373
* `Microsoft.AspNetCore.SystemWebAdapters.ISessionManager`: Accepts an <xref:Microsoft.AspNetCore.Http.HttpContext> and session metadata, returns an `ISessionState` object
7474
* `Microsoft.AspNetCore.SystemWebAdapters.ISessionState`: Describes session object state and backs the <xref:System.Web.SessionState.HttpSessionState> type
7575

76-
### Shared session state requirements
77-
78-
> [!NOTE]
79-
> To use session state with System.Web adapters, endpoints must explicitly opt-in via metadata implementing `ISessionMetadata`.
80-
81-
In order to support <xref:System.Web.HttpContext.Session>, endpoints must opt-into it via metadata implementing `ISessionMetadata`.
82-
83-
**Recommendation**: To enable this on all MVC endpoints, there is an extension method that can be used as follows:
84-
85-
```cs
86-
app.MapDefaultControllerRoute()
87-
.RequireSystemWebAdapterSession();
88-
```
89-
90-
This also requires some implementation of a session store. For details of options here, see the sections below on different session approaches.
91-
9276
## Built-in ASP.NET Core session state
9377

9478
Choose this approach when you're performing a complete migration and can rewrite session-related code to use ASP.NET Core's native session implementation.
@@ -184,7 +168,7 @@ Out of the box, there is a simple JSON serializer that allows each session key t
184168

185169
Call `AddRemoteAppSession` and `AddJsonSessionSerializer` to register known session item types:
186170

187-
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/remote/Program.cs" id="snippet_Configuration" :::
171+
:::code language="csharp" source="~/migration/fx-to-core/areas/session/samples/remote/Program.cs" id="snippet_RemoteConfiguration" :::
188172

189173
**ASP.NET Framework configuration:**
190174

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
SystemWebAdapterConfiguration.AddSystemWebAdapters(this)
2-
.AddJsonSessionSerializer(options =>
3-
{
4-
// Serialization/deserialization requires each session key to be registered to a type
5-
options.RegisterKey<int>("test-value");
6-
options.RegisterKey<SessionDemoModel>("SampleSessionItem");
7-
})
8-
// Provide a strong API key that will be used to authenticate the request on the remote app for querying the session
9-
// ApiKey is a string representing a GUID
10-
.AddRemoteAppServer(options => options.ApiKey = ConfigurationManager.AppSettings["RemoteAppApiKey"])
11-
.AddSessionServer();
1+
public class Global : HttpApplication
2+
{
3+
protected void Application_Start()
4+
{
5+
SystemWebAdapterConfiguration.AddSystemWebAdapters(this)
6+
.AddJsonSessionSerializer(options =>
7+
{
8+
// Serialization/deserialization requires each session key to be registered to a type
9+
options.RegisterKey<int>("test-value");
10+
options.RegisterKey<SessionDemoModel>("SampleSessionItem");
11+
})
12+
// Provide a strong API key that will be used to authenticate the request on the remote app for querying the session
13+
// ApiKey is a string representing a GUID
14+
.AddRemoteAppServer(options => options.ApiKey = ConfigurationManager.AppSettings["RemoteAppApiKey"])
15+
.AddSessionServer();
16+
}
17+
}

aspnetcore/migration/fx-to-core/areas/session/samples/remote/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
});
99
// </snippet_Serialization>
1010

11-
// <snippet_Configuration>
11+
// <snippet_RemoteConfiguration>
1212
builder.Services.AddSystemWebAdapters()
1313
.AddJsonSessionSerializer(options =>
1414
{
@@ -25,6 +25,16 @@
2525
options.ApiKey = builder.Configuration["RemoteAppApiKey"];
2626
})
2727
.AddSessionClient();
28+
// </snippet_RemoteConfiguration>
29+
30+
// <snippet_Configuration>
31+
builder.Services.AddSystemWebAdapters()
32+
.AddJsonSessionSerializer(options =>
33+
{
34+
// Serialization/deserialization requires each session key to be registered to a type
35+
options.RegisterKey<int>("test-value");
36+
options.RegisterKey<SessionDemoModel>("SampleSessionItem");
37+
});
2838
// </snippet_Configuration>
2939

3040
var app = builder.Build();

0 commit comments

Comments
 (0)