0

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 Session. 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.

1 Answer 1

1

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"]);
Sign up to request clarification or add additional context in comments.

6 Comments

This also doesn't work. 'The type or namespace name 'Httpcontext' could not be found (are you missing a using directive or an assembly reference?)'
Do you have reference to System.Web.Dll? It should be, or you can add it manually.
Yes I have, just checked.
so, you have to add using System.Web; in using section.
I didn't saw that you edited your answer HttpContext.Current.Session and didn't understand right. But It still doesn't work because I can't just call it like that, HttpContext should be set to something?
|

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.