November 07, 2011

Force User Roles Update via DotNetNuke

One of the things that I have been finding that I do a lot recently is updating user security roles based on actions either taken by the users or actions that have been taken by others.  Doing so is quite simple from a DotNetNuke API perspective but how do you go about actually forcing the role membership change right away?  That is what I'll talk about in this post.

For performance and other considerations DotNetNuke uses a cookie to store users role information, encrypted and refreshed every 3 minutes by default.  In most cases this isn't a big deal as users role memberships do not change that often.  But in cases of users that want to get access, or remove access to different sections that can be a long time.  So how do we resolve this?

It is quite easily to simply expire the cookie, the next request by the user will get the values and they will have any access that they need.  Simply add the following code to your module.

var cookie = new HttpCookie("portalroles");
cookie.Expires = DateTime.Now.AddYears(-2);

That is all you have to do.  Simply expire the portalroles cookie and DNN will rebuild it on the next request!

tags: C#, DNN Development, Quick Tips
comments powered by Disqus

Content provided in this blog is provided "AS-IS" and the information should be used at your own discretion.  The thoughts and opinions expressed are the personal thoughts of Mitchel Sellers and do not reflect the opinions of his employer.

Content Copyright

Content in this blog is copyright protected.  Re-publishing on other websites is allowed as long as proper credit and backlink to the article is provided.  Any other re-publishing or distribution of this content is prohibited without written permission from Mitchel Sellers.