I have some 10 permission in my table. Some users have all 10 permissions.
Each page in the website have to check whether the user have the particular permission.
In the home page I can do a query and store the permission list to a list box, and check whether Permission1 is in the list box, when I navigate to other page Again I have to check whether the permission is present in the list box.
Here the list box is in home page and I will not be able to access it in page2.
I have to check permission in page load in page 2.
How can I access the list of permission in page2 can I add to session?
Is there any better way to do this?
You could store your data in the session variable, but I don’t like that option at all. The Session variable relies on keys to extract its values, it is not strongly typed, and if you are load balancing your application, you need a more elaborate way to keep sessions synchronized across servers.
We use for that type of requirement a Class library that contains a Singleton for the particular data we need to retrieve. The example below will retrieve from the database the list of Permissions only once, and cache it in the singleton. It is accessible from all your pages.
This should meet your requirements.