I need to store a globally accessible list in my C#/ASP project – Storing it in the global app on the server instead of the database – as the data is only needed when the app is running.
So far I have tried to create a list in the application start (Global Asax)
activePages= new List<ActivePage>(); Session["activePages"] = activePages;
Which obviously fails as I cant set the Session at this point. What is the correct way?
Ideally, I want to be able to set up a blank list when the App starts, and add to the list from any session (i.e. I could add to this list from my PC and Laptop at the same time)
I already have the code to do all the adding and management, but cant find a way to globally persist this list. Also, How would I then use this list on other pages in my app? I’ve not really had to touch the global asax before.
you need to have a look at Application State. Using the
Sessionwill no solve your problems as for each user visiting your application, a new session will be created. Also, after some time of inactivitySessionis destroyed.