Hey Westa, I think I figured it out. Had to go into the core dnn source code to find the answer, but it seems to be working pretty well. You and another person I asked both mentioned that the cached user info only gets wiped out on logout...so that is where I went to find the code.
I hope one of the core developers sees this and corrects me if I am doing something that would hurt me down the line.
Otherwise...this is what I did:
//*** Add/Remove the roles normally with the roles controller ***
Here is what does updates the cached user info
string cached_roles = getCachedUserRoles();
//Set the new roles to the users cache
if (cached_roles != null)
{
//Add the role name to the list
cached_roles = String.Concat(cached_roles, ";", <<Name of the new role>>);
//Updae the cached user info with the new list of roles
((UserInfo)Context.Items["UserInfo"]).Roles = cached_roles.Split(';');
}
/// <summary>
/// Method to retrieve the cached roles from the cookie
/// </summary>
/// <returns></returns>
private static string getCachedUserRoles()
{
if (HttpContext.Current.Request.Cookies["portalroles"] != null)
{
// get roles from roles cookie
if (!HttpContext.Current.Request.Cookies["portalroles"].Value.Trim().Equals(""))
{
//Retrieve the roles
FormsAuthenticationTicket RoleTicket = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies["portalroles"].Value);
//Set the roles
return RoleTicket.UserData;
}
}
return null;
}
The above will add a new role on the fly...Obviously if you want to remove the role, just call the same code, but instead of added to the list...remove the role name from the list.
Let me know if you have any questions or problems.
Hope this helps you out!
Gary