CacheRolesInCookie - non-caching roles

I am trying to use forms authentication with the following configuration settings. I set cacheRolesInCookie to true. However, I find that the RoleProvider GetRolesForUser method is called for each request. I see that cookie.asproles is created and contains data in it, but it seems to be ignored.

Has anyone encountered this problem before? Any help would be greatly appreciated.

  <authentication mode="Forms"> <forms name=".formsauth" loginUrl="~/Login.aspx" defaultUrl="~/Home.aspx" slidingExpiration="true" timeout="20" path="/" /> </authentication> <!-- Membership Provider --> <membership defaultProvider="CustomMembersipProvider"> <providers> <add name="CustomMembersipProvider" type="Company.Membership.CustomMembersipProvider" /> </providers> </membership> <!-- Role Provider --> <roleManager defaultProvider="CustomMembershipRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".asproles" cookieTimeout="20" cookieSlidingExpiration="true" cookieProtection="All" createPersistentCookie="true"> <providers> <add name="CustomMembershipRoleProvider" type="Company.Membership.Provider.CustomMembershipRoleProvider" /> </providers> </roleManager> 

Thanks a lot Naren

+4
source share
2 answers

What is the RolePrincipal method called? IsInRole uses the cache in the .asproles cookie, but the GetRoles method starts calling your RoleProvider once per request.

+1
source

After updating my application to MVC5.Net 4.5, the same problem appeared. To fix this, you will need to save the cookie yourself. See how here .

0
source

All Articles