Reputation: 12748
I need a variable that will be used everywhere (controller, view, master page, ...). I was thinking of putting it in the TempData. Where is the best place to put an object there?
I thought of Page_Load but that's done after the controller.
I thought of the controller Initialize but the TempData seems to be cleared after that.
Upvotes: 0
Views: 923
Reputation: 12748
I couldn't use a session because the data could change on every request. I decided to initialize everything in the OnActionExecuting of the controller and it's working great.
Upvotes: 1
Reputation: 5789
You should use a Session variable rather than TempData. Variables stored in TempData will be destroyed after one request: Difference Between ViewData and TempData?
Here is a link documenting the various Client and Server side storage options in Asp.net http://www.dotnetfunda.com/articles/article61.aspx
Upvotes: 0