HoTTab1CH HoTTab1CH - 4 months ago 24
ASP.NET (C#) Question

Can't declare Session variable in sharepoint page

So I need to store some data on my page (webpart) in variables after post request.

But when I try to declare it for example

Session["test value"] = someValue;
Visual studio just don't recognize
. I checked namespcses, wrote probably everything that is possible but it still can't see Session.

What am I doing wrong?
And if it is not possible for some reason in my case, how should I save Variables after post request? Static class is not an option since he in only 1 for all users and I need to store different data for different users.


Probably HttpContext.Current.Session is what you need

Example of usage:

HttpContext context = HttpContext.Current;

Store data

context.Session["FirstName"] = firstName;

Retrieve data

firstName = (string)(context.Session["FirstName"]);