0

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

3
  • Sessions have not significantly changed from 4.5 -> 5 so just use the example code here -> msdn.microsoft.com/en-us/library/… and be done with it. Commented May 30, 2016 at 16:15
  • Wow, I've been looking at stuff that made it seem more difficult than it was, thank you! Commented May 30, 2016 at 16:21
  • Normally, you should not need Session State directly in ASP.Net MVC, although we use Session State and View State extensively in ASP.Net Web Form. What kind of information are you trying to persist? Commented May 30, 2016 at 16:50

1 Answer 1

1

Assign it like this

Session["User"] = "Current";

Access it like this

if(Session["User"]!=null)
{
    string userName = Session["User"].ToString();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.