In MVC 5 you could assign a value to session in global.asx when the session started. Is there a way you can do this in .Net Core MVC? I have session configured but in the middleware it seems to get called on every request.
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- Dotnet Core API - Get the URL of a controller meth
- Why am I unable to run dotnet tool install --globa
- parameters in routing do not work MVC 3
- Singleton with AsyncLocal vs Scope Service
相关文章
- How to get a list of connected clients on SignalR
- DotNet Core console app: An assembly specified in
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- EF Core 'another instance is already being tra
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
nercan's solution will work, but I think I found a solution that requires less code and may have other advantages.
First, wrap DistributedSessionStore like this:
Then register this new class in Startup.cs:
Full code is here: https://github.com/SurferJeffAtGoogle/scratch/tree/master/StartSession/MVC
I use it in a live project. It works correctly. if you want to keep it when the application stops. You should use DistributedCache. For example, I'm using DistributedRedisCache.
Add to startup this code;
And add new session extension;
And use get or set same this;
you need this extension;
I suppose it will work.
and add startup.cs Configure method after app.UseSession();