I'm working on a web application in ASP.NET MVC. When the user logs in, I want to retrieve his navigation (varies between user accounts) and his information from the database, and keep the info between controllers.
I'm displaying the navigation in _Layout.cshtml
so I'm wondering best practices to pull the navigation and other user info from the database and storing it between controllers. This information is only retrieved once and stored through-out the user "log-in session".
What is the ideal solution? Should I create a BaseController
which other controllers inherit and put my logic in the constructor and put the info in a global ViewBag
? Or should I use the Session
object in the Login
method? Or should I create a static method and call it directly from _Layout.cshtml?
What should I do? I want to do this globally once, so I don't have to do this in each controller action.