Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session Variables in ASP5/MVC6

In MVC5, I used to use my session variables like this from System.Web

PayPalHandler.ExecutePayment(
    Convert.ToString(Session["paymentId"]), 
    Convert.ToString(Session["payerId"]));

In ASP5/MVC6, this is no longer an option as System.Web does not exist. What is the proper equivalent way of using session variables in the new framework? Documentation is still very scarce.

like image 415
Corey Chase Avatar asked Jun 22 '15 22:06

Corey Chase


1 Answers

you need to install Nuget package

Microsoft.AspNet.Session

and use it using Context

Context.Session.SetString("Name", "My Name"); //Set
var name = Context.Session.GetString("Name");//Get

Good explanation can be found at http://www.mikesdotnetting.com/article/270/sessions-in-asp-net-5

like image 156
Thakur Avatar answered Oct 21 '22 07:10

Thakur