title: ASP.net MVC Membership Redirect Depending on Role
body: <p>I have two types of roles [Admin, HelpDeskAdmin].</p>
  
  <p>I have  a single logon view(both users go to same link to login) and I want to check their role once logged in and redirect to their respective admin pages once authenticated.  The code below doesn't identify the logged in user as being in the role the first time and reloads the logon page, the second time they logon it redirects correctly.</p>
  
  <p>Does this have something to do with the authentication cookie not being in place when it checks the first time?  How could I accomplish this scenario?</p>
  
  <pre><code>[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 (!String.IsNullOrEmpty(returnUrl))
       {
           return Redirect(returnUrl);
       }
       else
       {
           if (Roles.IsUserInRole("Admin"))
           {
                //go to admin landing page
                return RedirectToAction("Index", "Manage"); 
           }
            else if (Roles.IsUserInRole("HelpDesk"))
            {
                //go to helpdesk landing page
                return RedirectToAction("Index", "Interview"); 
            }
            else /******FIRST TIME THROUGH IT ALWAYS GOES HERE *******/
               return RedirectToAction("Index", "Home");  //not in any of those roles
        }
  }
  else
       {
         ModelState.AddModelError("", "The user name or password provided is incorrect.");
        }
  }
   // If we got this far, something failed, redisplay form
  return View(model);
  } 
  </code></pre>