Im using a base controller & OnActionExecuting to get ‘common’ site data that I want to show & keep accross most page’s (name, ID etc… not more than 4/5 fields)
The Method in OnActionExecuting reads the database & saves to ViewBag which Ipick up in my Views but I cant help thinking this is a waste as it needs a DB call for every OnActionExecuting.
How can consolodate these DB calls and slim down the DB access?
What I have done on a recent project is during Login I get the ‘common’ data which in this case was UserID, FirstName and an ImageName, I saved it in the Auth Ticket like this :
I then retreive this Cookie when the data is needed and get the data out of it like this :
Please Note : This is only good for static data that you know wont change during the login session & be careful what you post in this Cookie.
Don’t bloat the cookie either keep the fields to a minimum, max is 4K but I aim for 500-1000 bytes.