For my application when the user logs in I need to check if they have any roles assigned to them and if they don’t assign them a basic role. Also based on their role I have to redirect them to certain pages. But I can’t find a way to check/set user’s roles when they sign in.
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
if(User.IsInRole("User"))
//This won't work becauser User is not populated yet. It will be populated only on next request for some reason that has to do with setting cookies
}
Any ideas how to work this out?
Apparently
Roles.IsUserInRolemethod allows to pass string as username, so it makes possible to check users membership without calling the User object.