I am trying to redirect the user to the appropriate page on login. So I check to see if they are in a role and then redirect based on membership. However, Roles.IsUserInRole() doesn't seem to work. Plus when I use Roles.GetRolesForUser("username") I get "System.String[]". I am using the default simplemembership in mvc4. I can see the users created in the database and are linked to the appropriate roles. Also, when I use the [Authorize Roles..] that works fine. Here is my login(Pretty much the default login with my Role Check and redirect added.
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{ //Get list of roles to print
Session["FName"] = Roles.GetRolesForUser(model.UserName);
if(Roles.IsUserInRole(model.UserName,"User")){
return RedirectToAction("Index","UserLanding");
Session["FName"] = "User in User group";
}
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
I would expect when a user logs in in the "user" group they get redirected to the UserLanding Congroller Index page. However, they always get redirected to the Home page.