Reputation: 3312
I have a MVC application, I am using entity framework, There is a master table whose data is accessed among different views & controllers by all users.
I want to keep the data of this master table into some shared variable/session or anything so that it can be accessed by all users. As this is a master table it is data is common for all.
I tried using TempData, ViewBag but there data does not persist if we redirect to different views & controllers. I tried sessions as well, but I do not want to have each user keeping a copy in memory.
What is the best way to store such data in MVC application
Atul Sureka
Upvotes: 1
Views: 829
Reputation:
You can put them in the Application:
Application["GlobalVar"] = 1234;
They are only global within the current IIS / Virtual applicition. This means, on a webfarm they are local to the server, and within the virtual directory that is the root of the application.
Upvotes: 0
Reputation: 17182
Use Runtime Cache object in ASP.Net MVC to keep all the common data. Cached data can be accessed fast and we have other benefits like expiring cache etc.
Upvotes: 3
Reputation: 8188
You are looking for Application State http://msdn.microsoft.com/en-us/library/bf9xhdz4%28VS.71%29.aspx it is like session state but shared across all connected users (global session).
Upvotes: 2