Reputation: 962
How can I store data in memory of asp.net mvc application which can be accessed by all users logged in.
Upvotes: 0
Views: 6229
Reputation: 594
You can use a static variable. If you have some static Constants class, just create a static list or a static variable.
public static List<string> commonList = new List<string>
Upvotes: 1
Reputation: 962
Something like that will work for me:
Application.Lock();
Application["PageRequestCount"] =
((int)Application["PageRequestCount"])+1;
Application.UnLock();
Here I can save data from user and store it in a data object which will be in application - stored in memory. My idea is to make a chat, but not use a db, relying solely on RAM. So every user will have their messages in their own session, when the user want to submit a message, it will lock and save in messages collection common for all users and the unlock. When the user read - there will be no need for unlocking. Just elaborating about possible use of that, but the answer of the question is the 3 lines source code.
Upvotes: 0
Reputation: 172628
You can store the value in your application using something like this:
protected void Application_Start()
{
HttpContext.Current.Application["somevar"] = "0";
}
Upvotes: 0