3

In my web.config I have the Role Manager configured as follows:

<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" 
cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" 
cookieSlidingExpiration="true" cookieProtection="All">

however in our custom RoleProvider it would seems that the GetRolesForUser method is always being called, rather than as I would have expected, the RoleManager serving up the roles from its cookie.

We're using something like to get the roles for a user:

string[] myroles = Role.GetRolesForUser("myuser");

Is there something that I'm missing in the configuration, or in the use of the RoleManager

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Ralph Shillington
  • 20,718
  • 23
  • 91
  • 154
  • 1
    There's a typo in your code sample - cacheRolesInCookie="ture". – Steve May 07 '09 at 17:40
  • A straight copy & paste of your config works for me, except I also specify a default provider. – Kevin Pullin May 12 '09 at 23:48
  • Maybe this link describe the same problem you are experience? http://connect.microsoft.com/VisualStudio/feedback/details/104688/rolemanager-cacherolesincookie-option-does-not-work I also have this problem, and i can´t get my custom rolemanager to store the roles into a cookie. – Jonas Mar 08 '11 at 19:33

2 Answers2

4

You are missing defaultProvider="yourRoleProviderName" in your web.config .

Do you call the method below for any user or for current user only? Cookie caching works only for current user roles.

Role.GetRolesForUser("myuser");

Check that .ASPROLES cookie is sent to browser after the fist call of IsInRole or GetRoles method.

Andrej Golcov
  • 648
  • 5
  • 12
1

It might work better if you were to change the value in your cacheRolesInCookie to true.

Jordan S. Jones
  • 13,703
  • 5
  • 44
  • 49