How to direct each user to your page corresponding to your access profile using asp.net identity with roles

1

I have 3 profiles registered in the database SQL Server, they are Master, Admin and User, when you log in as you would for each user to be directed to your permission view. by default the route is loading the home / index.

      // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        // Isso não conta falhas de login em relação ao bloqueio de conta
        // Para permitir que falhas de senha acionem o bloqueio da conta, altere para shouldLockout: true
        var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Tentativa de login inválida.");
                return View(model);
        }
    }

how would I implement if, tried and did not compile, with your information above. @ gilberto-b-terra-jr

    
asked by anonymous 09.12.2016 / 21:02

1 answer

0

Redirect checking the user's role in the AccountController login method?

UPDATED

switch (result) 
{
    case SignInStatus.Success:
        if (User.IsInRole("Master"))
            return RedirectToAction("Index", "Master");

        if (User.IsInRole("Admin"))
            return RedirectToAction("Index", "Admin");

        return RedirectToAction("Index", "Home");

    case SignInStatus.LockedOut:
        return View("Lockout");
    case SignInStatus.RequiresVerification:
        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
    case SignInStatus.Failure:
    default:
        ModelState.AddModelError("", "Tentativa de login inválida.");
        return View(model);
}

Hello friend, this is a simple example, see if you can get there, let us know if you still can not! Note that I put a if (User.IsRole () to redirect each user profile to different controllers / actions!

    
23.12.2016 / 19:35