0

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.

tereško
  • 57,247
  • 24
  • 95
  • 149
the_lotus
  • 12,421
  • 2
  • 33
  • 52

2 Answers2

1

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.

the_lotus
  • 12,421
  • 2
  • 33
  • 52
0

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

Community
  • 1
  • 1
Bojin Li
  • 5,719
  • 2
  • 23
  • 35