is it possible to store list to session variable in Asp.net C# ?
Yes, you can store any object (I assume you are using ASP.NET with default settings, which is in-process session state): Session["test"] = myList; You should cast it back to the original type for use: var list = (List<int>)Session["test"]; // list.
Solution 4. Session variable can store large amount of data, including class, dataset.
It means you need persist your session in database at appropriate point. You may use out of process session storage (database or different server) - you have to mark your shopping cart class as serializable in such case. There is performance cost to out-of-process sessions.
Session state can be stored in one of the following modes: In - Process: Stored in the same ASP.Net Process. State Server: Stored in the some other system. SQL Server: Stored in the SQLServer database.
Yes, you can store any object (I assume you are using ASP.NET with default settings, which is in-process session state):
Session["test"] = myList;
You should cast it back to the original type for use:
var list = (List<int>)Session["test"]; // list.Add(something);
As Richard points out, you should take extra care if you are using other session state modes (e.g. SQL Server) that require objects to be serializable.
Yes. Which platform are you writing for? ASP.NET C#?
List<string> myList = new List<string>(); Session["var"] = myList;
Then, to retrieve:
myList = (List<string>)Session["var"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With