Earlier we have Session
to manage state in an ASP.NET web applications. I'm trying to create a simple vNext MVC application where I need to do some state management. Now because System.web
is gone how can I use Session
in MVC 6 applications. Is it still available in Microsoft.AspNet.Mvc
or anywhere else or is there some other server side state management available and how to use? Please help..
Asked
Active
Viewed 1,708 times
7

Eilon
- 25,582
- 3
- 84
- 102

Rahul Chakrabarty
- 2,149
- 7
- 39
- 70
-
I haven't dug deep into vNext yet, but to my understanding, `System.Web` is not some forbidden thing, now. If you need it, you include it. The point was being able to remove it if it *wasn't* needed, such as in a Web API running self-hosted. So, if you need `Session` add the `System.Web` reference and bootstrap it. – Chris Pratt Aug 06 '14 at 14:27
-
It is important to point this out: System.Web is only available when running on Desktop CLR (.net 4.5.1). If you want to run on the Cloud optimized CLR (CoreCLR) System.Web is gone – Victor Hurdugaci Aug 06 '14 at 15:45
-
@VictorHurdugaci Well, I tried to use System.Web. In which I found only following three classes "AspNetHostingPermission", "AspNetHostingPermissionAttribute" and "AspNetHostingPermissionLevel" There is no "HttpSessionStateBase" abstract class Even I tried to create a MVC 5 controller (using System.Web) but there is no System.Web.Mvc. Haven't found any nuget to refer the dependency in project.json – Rahul Chakrabarty Aug 07 '14 at 05:40
-
@Riki I have updated my answer given that ASP.NET vNext has a new session state middleware you can check out. – Eilon Nov 03 '14 at 03:49
-
Possible duplicate of [How to implement Session State in ASP.NET vNext MVC 6](http://stackoverflow.com/questions/25077298/how-to-implement-session-state-in-asp-net-vnext-mvc-6) – JabberwockyDecompiler Nov 09 '15 at 15:47
1 Answers
7
Update 11/2/2014
The ASP.NET team has started building a new session state middleware to enable session state in ASP.NET 5. 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);
Original answer
Session state is not yet implemented in ASP.NET vNext, but it is in the plans. You cannot use System.Web's session state at all because even if the app is running on full .NET, the session state implementation in System.Web is not compatible with ASP.NET vNext.
-
-
-
I dont see app.UseSession(); is valid anymore. What is the status now? – Vu Nguyen Aug 17 '15 at 08:11
-
@VuNguyen it's still there. Do you have a reference to `Microsoft.AspNet.Session` in the `project.json` file? What error(s) are you getting? – Eilon Aug 18 '15 at 01:14
-
I see the repository on GitHub, and when I get `Microsoft.AspNet.Session` from nuGet, I receive "Error in restoring". The warning mark is at reference node of `Microsoft.AspNet.Session` . – Vu Nguyen Aug 18 '15 at 03:21