Assigning a user to a role
I've created a role (Affiliates) and set some page permission to require that role.
When a user enrolls has an affiliate, I assign him to that role, as such:
RoleManager roleManager = RoleManager.GetManager();
Role role = roleManager.GetRole(
"Affiliates"
);
roleManager.Provider.SuppressSecurityChecks =
true
;
try
roleManager.AddUserToRole(user, role);
roleManager.SaveChanges();
finally
roleManager.Provider.SuppressSecurityChecks =
false
;
I believe Sitefinity does some kind of caching on user roles. For example, when you de-admin someone, you need force log them out or else Sitefinity will still treat them as admin with all privileges.
It does look like something like that, although logging out than back in does not solve the problem all the time.