User Added to Role Can't immediately see menu items tied to role.

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
9/8/2009 9:19:30 PM
Gravatar
Total Posts 131

User Added to Role Can't immediately see menu items tied to role.

If a user is added to a new role, do they need to logoff before they will see any menu items that have permission visible only if they have that role? I've created functionality that allows users to purchase a subscription, and the subscription grants them access to new roles. But after the purchase, and after the new role is added to user_roles, the user can not see the new menue items.

Is there some way to reset the session to allow them to take on the new role permission, or, as I suspect, clear the menu from cache to allow them to see the new menu items?

Thanks

 

9/8/2009 10:06:44 PM
Gravatar
Total Posts 131

Re: User Added to Role Can't immediately see menu items tied to role.

I figured this out. Joe had a nice method in the mojoRoleProvider that I copied, modified a bit and used in my StoreHelper.

The method is below for anyone who needs it.

 

public static void RefreshRoleCookie()

{

string[] currentUserRoles = new string[0];

String hostName = WebUtils.GetHostName();

SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

if (siteSettings != null)

{

string roleCookieName = SiteUtils.GetRoleCookieName(siteSettings);

currentUserRoles = SiteUser.GetRoles(siteSettings, HttpContext.Current.User.Identity.Name);

string roleStr = "";

foreach (string role in currentUserRoles)

{

roleStr += role;

roleStr += ";";

}

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(

1, // version

HttpContext.Current.User.Identity.Name, // user name

DateTime.Now, // issue time

DateTime.Now.AddHours(1), // expires every hour

false, // don't persist cookie

roleStr // roles

);

string cookieStr = FormsAuthentication.Encrypt(ticket);

HttpCookie roleCookie = new HttpCookie(roleCookieName, cookieStr);

roleCookie.Expires = DateTime.Now.AddMinutes(20);

roleCookie.HttpOnly = true;

roleCookie.Path = "/";

HttpContext.Current.Response.Cookies.Add(roleCookie);

}

 

You must sign in to post in the forums. This thread is closed to new posts.