Monday, March 12, 2012

Refreshing user roles using custom role provider without logging out

Recently, I had a situation where the user's roles needed to refresh to allow the user to gain access into some site's resources. We were using a custom role provider and custom membership provider to manage our users. We were able to assign roles to user when they click on a button control. But, the problem we faced with this is that the user has to log out and log back in to get the role he/she just got assigned. Obviously, no one liked it and it should be seamless to the end user.

After a long research it turns out to be that the SP 2010 somehow caches or stores the user's roles in memory until the user logs off or the session ends. so I was searching for a way to force SharePoint to refresh the role assignments for the current user. I came across this great post

Force FBA Token Refresh 

You do need to have your own global.asax file to the webroot (where your web.config lives for the front-end servers).

After implementing the above method everything worked perfectly. I found that this particular event handler code is getting called for every web request to the server. so if you are planning on doing any costly operation, do it with caution.

Thanks
Senthil S