Frage

My first question here. For an MVC 4 CMS application that I am building, I am making use of the SimpleMembersshipProvider. In it, I have users that are assigned to specific roles. Upon login, I want to check what role these users have, and then redirect them to their specific part of the application.

So when the user logs in, I check using:

if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
  if (User.IsInRole("Organisation"))
  {
    return RedirectToAction("Index", "Organisation");
  }
}

This never works the first time around, but as soon as I type in the URL after the code has executed, or if I do this a second time, it works perfectly. Is the Role information not available upon login? Is there another way I need to handle this perhaps?

Thanks for your answers and my appologies if this is an easy question.

War es hilfreich?

Lösung

you have to write that if section after redirection. roles don't work before page refresh.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top