Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Dynamically appling the roles to usersDynamically appling the roles to users
Previous
 
Next
New Post
10/30/2009 6:43 AM
 

I know this is an old post, but I wanted to document wherever this code exists that there is a better way of refreshing the user's roles cookie, which is with the PortalRoles.ClearRoles() shared method. If you call this line and then clear the user's cache, a subsequent page refresh will relaod the user's roles from the database.

Using the API is always a better way to work with the system if possible because it allows for changes to be made to the internal workings. I'm currently working on a resolution for the limit on the number of roles in which a user exists prior to the system falling over because of truncation of data (causing a decryption exception) in the user's roles cookie. That changes the contents of the cookie, and your code would cause failures in that instance.

To summarise,

C#

<code>
   //Clear the user's cached/stored role membership, will reload on next page cycle
   PortalSecurity.ClearRoles();
   DataCache.ClearUserCache(PortalId, UserInfo.Username);

   //Load the current roles into the user's current context for use in this page cycle
   RoleController roleControl = new RoleController();
   UserInfo.Roles = roleControl.GetRolesByUser(Me.UserId, Me.PortalId);
</code>

or VB

<code>
   'Clear the user's cached/stored role membership, will reload on next page cycle
   PortalSecurity.ClearRoles()
   DataCache.ClearUserCache(PortalId, UserInfo.Username)

   'Load the current roles into the user's current context for use in this page cycle
   Dim roleControl As New RoleController
   UserInfo.Roles = roleControl.GetRolesByUser(Me.UserId, Me.PortalId)
</code>

will cause a user's role list to be reloaded on the next page refresh. The third and fourth lines are only required when there is no redirect happening at the end of what you are doing, making the roles change visible in the current page cycle. Clearing the user's roles and the cache cause them to be reloaded automatically on the next page cycle, but depending on what you are doing that may be too late.

I hope this helps and finds favour with people! It's a more community-friendly way of working as it allows interoperability with custom membership HttpModules that may modify what the roles cookie contains. The current contents of the roles cookie are a problem for some people on large systems with many role memberships for each user, which makes the roles cookie contents a candidate for being changed in the future.

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Dynamically appling the roles to usersDynamically appling the roles to users


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