New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Roles cache when updating roles assigned to a user through databaseRoles cache when updating roles assigned to a user through database
New Post
12/6/2017 10:14 PM


I'm doing some user & role handling using the database instead of DNN API. I assign roles to existing users invoking proper stored procedures and everything seems to be working fine except for a glitch I've found:

- When I assign a new role to an existing user that is currently logged in to the site (or was online recently) it seems the site doesn't acknowledge the role change for that user for some time (usually 10 or 15 minutes). Even when that user signs off and re-authenticate the new roles still don't seem to take effect until some time later. 

- I'm able to see the roles assigned to the user (within DNN Admin pages) since the very beginning, the roles are being successfully assigned, the problem seems to be the site not knowing there was a change.

- If the user is new (I create a new user with roles assigned) when the user authenticates everything seems to work fine and all the roles are acknowledged.

- If the user is not new, but wasn't online for a while, new roles are recognized as soon he / she authenticates into the site.

- The problem gets automatically solved after some time or if the site or the general cache are reset. 

- If I assign the same roles through DNN Admin section the site recognizes them right away, even when the target user is currently online and without the need to log off and re authenticate.

- I was able to verify the same problem in different DNN installations. All with version 7+

My guess is that there is some kind of "roles cache" going on in there that stores user information of online or recently online users and that is the cause of the problem. In addition, The fact that the roles change is working properly when done through DNN admin pages tells me that there must be an internal call to a "Reset Roles Cache" functionality or something similar. Does this make sense? I wasn't able to confirm any of this on my research.

My question is: Does the "Roles Cache" exists? If so, is there any way I can reset it full or for a particular user programmatically (without completely reset the whole site cache, of course)? Is there any configuration setting that controls this behavior? I've found that the "UpdateUser" stored procedure has a "RefreshRoles" parameter but passing "true" in there doesn't seem to change anything from me. Do you know what does that parameter means?

Please note that I'm sure switching to DNN API will very likely solve the problem but that is not an option right now for me. I would really appreciate if someone can put me in the right direction.

Thanks in advance.

New Post
12/6/2017 11:57 PM
if you bypass DNN API, you don't only risk your code to break on a future platform upgrade, but you are also responsible to invalidate the DNN object cache, which stores retrieved objects from the database. This applies to all objects: websites (portals with portal settings, portal aliases, portal languages etc.) pages (tabs, tabsettings, tabversions), modules (modules, tabmodules, module settings, ...), but users and roles and role membership as well. You either need to use DNN API (suggested), invalidate the cache within your module or clear all website cache after you applied your changes.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
New Post
12/7/2017 4:00 AM

Thank you Sebastian for you quick response.

I completely understand and agree with you regarding the need to use DNN API. The problem is that we are maintaining some legacy code and we are not currently ready to replace all that. We're definitely going to do it in the near future but right now I really need a workaround. For example, do you know how to invalidathe the roles cache for a particular userId?

Thanks again

New Post
12/7/2017 8:32 AM

the easiest way is to restart the application pool, either in DNN (as Host, goto Tools and click "Restart Application) or you can use IIS manager (when you have access to the server console).

Happy DNNing!

Michael Tobisch
DNN★MVP - The most vibrant community around the DNN-platform
New Post
12/7/2017 12:50 PM

Thanks Michael, but I need a way to do it:

1) Programmatically. I need to do this every time my module's code assign new roles.

2) Not for the whole site since resetting the site cache or the application pool will destroy sessions of users online.

I was hoping there was an API call (I can use DNN API for this) that will allow me to reset the roles cache for a specific user (not the whole site) on demand. For example something like RolesCacheManager.Invalidate(userId). I've searched around for something like this but without luck. Isn't there such thing or it is just not exposed?



HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Roles cache when updating roles assigned to a user through databaseRoles cache when updating roles assigned to a user through database

These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out