Reputation: 1444
I'm implementing custom Authorization with OpenId. In the database I have User Name (unique), OpenId (unique) and set of User Roles.
While the user is being Authorized, I set
//GetRolesFromTheDBAndAssignThemToTheUser(); how?
FormsAuthentication.SetAuthCookie(GetUserName(OpenId), false);
And using custom attribute on controller:
public override void OnAuthorization(AuthorizationContext filterContext)
{
//..some code
var user = filterContext.HttpContext.User; //I can get user
var roles = Roles; //I can get roles
var isAlowed = roles.Split(',').Any(user.IsInRole); //validate if user is alowed to use the current page or do other stuff
}
But how I can set specific Roles to the user in order to use HttpContext.User.IsInRole method?
Upvotes: 1
Views: 643