Here is a non-exhaustive list of where I've seen it done:
- Individually within each method of the controller
- In the controller's constructor
- As a property (lazy-initialized) of the controller
- In an ActionFilter, shoved into ViewBag
- In Global.asax Application_BeginRequest
- In an HttpModule
I can't identify a clear front-runner amongst all of those. What's worse, whenever I start a brand-new project, I tend to change it up, just because.
Does anyone have any battle-tested advice?