Petter Petter
Petter Petter

Reputation: 103

Create a session in ASP.NET MVC

I can't for the life of me figure out how to create / use sessions in my project
My target framework is 4.5.2

I've downloaded the NuGet package Microsoft.AspNet.Session
But all I can find online about sessions seems to be related do ASP.NET 5

How do you go about using sessions?

Thank you

Upvotes: 0

Views: 864

Answers (1)

Pawan Nogariya
Pawan Nogariya

Reputation: 9000

Assign it like this

Session["User"] = "Current";

Access it like this

if(Session["User"]!=null)
{
    string userName = Session["User"].ToString();
}

Upvotes: 1

Related Questions