I need to keep some static data about the user, after he has logged into my ASP.Net MVC 4 website. Everything is hook up in Castle Windsor container.
The login process calls an Authentication service, which returns the user data, that is needed for processing and other servicecalls later in a session.
I have looked at this post: MVC Custom Authentication, Authorization, and Roles Implementation. But the problem is that it uses servicelocation in a static class, which is problematic.
How should i store userdata for use throughout the session in a setup like this?
EDIT:
I’m using persistent cookies, so somehow i need to recreate my userdata, when a user returns to the site.
In your LogOn method once you have authorized the user and retrieved the user details from the database you could store them in the session:
and later when you need them:
As an alternativeyou couldwrite a custom MembershipProvider which will read this information from the session if present and if not it will query the database to retrieve it.
Another possibility is to have a custom Authorize attribute by overriding the AuthorizeCore method in which you could setup a custom principal containing the user details and reading the, from the session.