dotnet / dotnet/systemweb-adapters

WrappedAspNetCoreSession doesn't persist updated properties

Open
#698 2 comments 0 reactions 0 assignees View on GitHub
Needs: Triage :mag:
Dominant language
C#
Stars
384
Forks
76
Avg merge
2h 24m
Merged PRs (30d)
1

Description

### Describe the bug

Compare the behaviour of the following between .NET Framework and .NET Core's `AddWrappedAspNetCoreSession`:

- create a class with some simple value properties
- via `System.Web.HttpContext.Current.Session` either
- set a new instance of that class into session
- pull an existing instance of that class out of session
- update a property on the instance; do not explicitly write the instance back to `System.Web.HttpContext.Current.Session`
- read the property in a subsequent call

In .NET Framework, the updated value is automatically persisted into session at the end of the first call.

In .NET Core via `AddWrappedAspNetCoreSession`, the updated value does not appear to be persisted into session at the end of the call unless you manually push the instance back into `System.Web.HttpContext.Current.Session`.

`AspNetCoreSessionState` does not seem to track what values have been added or retrieved and re-push them to the underlying `_session` in `CommitAsync`.

Further, if you retrieve the same value from session twice in _one_ call, in Framework you get the same object, but in Core you get different objects. `AspNetCoreSessionState` does not seem to track what values have been pulled from the underlying `_session` and return the same instances.

### To Reproduce

Similar Web API code running in [Core](https://github.com/rawling/SwaSessionPersistence/blob/master/SwaSessionPersistence.Core/Controllers/WeatherForecastController.cs) and [Framework](https://github.com/rawling/SwaSessionPersistence/blob/master/SwaSessionPersistence.Framework/Controllers/ValuesController.cs).

Run via the [caller](https://github.com/rawling/SwaSessionPersistence/blob/master/SwaSessionPersistence.Caller/Program.cs):

Image

### Further technical details

Please include the following if applicable:

*ASP.NET Framework Application*:
- Technologies and versions used (i.e. MVC/WebForms/etc): WebApi. In-proc session provider. (Observed with SQL session provider too, but not tried with this repro.)
- .NET Framework Version: 4.8
- IIS Version: Express
- Windows Version: 10

*ASP.NET Core Application*:
- Targeted .NET version: 8 (observed in 10 too, but not tried with this repro)
- .NET SDK version:

Image

Contributor guide

Open the contributing guide

Research direction

Start with AspNetCoreSessionState, especially how values are retrieved and how CommitAsync handles the underlying _session. Run the linked SwaSessionPersistence Core and Framework controllers through the caller to compare updated-property persistence and repeated retrieval. Done means Core matches Framework for both behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
63/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.