In Visual Studio 2014, ASP.NET vNext, i am trying to implement Session State in MVC 6.I am not getting any Intellisense in Visual Studio to implement it.Please suggest me how to use it.
The ASP.NET team has started building a new session state middleware to enable session state in ASP.NET vNext. You can check out the Session repo, which has both the Session middleware, as well as a sample.
To enable session state in an app, call:
app.UseSession();
And to read/write from it:
var some_value = context.Session.GetInt("some_value").Value;
some_value++;
context.Session.SetInt("some_value", some_value);
Basically same question as How to do server side state management in vNext Web Applications - session state is not yet implemented in ASP.NET vNext.
As others have noted, TempData is not the same thing as Session State, it is merely built on top of it. (And it is also not yet implemented in ASP.NET vNext.)
I've written a blog post outlining the details of How to Implement Sessions in ASP.NET 5, MVC6. Updated for Beta8
It boils down to:
Microsoft.AspNet.Session
nuget package.services.AddSession()
to startup.csservices.AddCaching()
to startup.csapp.UseSession()
to startup.csHttpContext.Session
inside controllersIHttpContextAccessor
to get to the HttpContext outside of controllersIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With