How do I cache roles in ASP.NET 2.0?

From Guidance Share

Jump to: navigation, search

J.D. Meier, Prashant Bansode, Alex Mackman


If a user's browser accepts cookies, you can cache role information for that user in a cookie. To do so set the cacheRolesInCookie attribute to true on the <roleManager> element. On each page request, ASP.NET reads the role information for that user from the cookie. Role caching can improve application performance by reducing the number of lookups to the underlying role store. If the role information for a user is too long to store in a cookie, ASP.NET stores only the most recently used role information in the cookie and then looks up additional role information in the data source as and when required. To configure and enable role caching, set cacheRoleInCookie to true on the <roleManager> element as shown here.

<roleManager enabled="true" 
       cacheRolesInCookie="true" .../>

Note. When using role caching it's important to protect the authorization cookie.

More Information

For information on using role manager and role caching, see “How To: Use Role Manager in ASP.NET 2.0” at

Personal tools