使用不起作用的角色重定向

时间:2015-08-05 11:40:06

标签: asp.net-mvc

[ValidateAntiForgeryToken]

    [HttpPost]

    [AllowAnonymous]

    public    async   Task<ActionResult>   Index    (LoginModel   model, string  returnUrl)
    {


        if   (ModelState.IsValid)
        {
            var   loginbusiness =   new    LoginBusiness();
            var    result = a  wait   loginbusiness.LogUserIn(model, AuthenticationManager);

            var   roleManager  =  new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new DataContext()));
            var role = await roleManager.RoleExistsAsync(model.UserName);

            if (returnUrl == null && role)
            {
                if (User.Identity.IsAuthenticated && Roles.IsUserInRole(model.UserName, "Admin"))
                {
                    return RedirectToAction("Index", "Admin");
                }
                else if (User.Identity.IsAuthenticated && Roles.IsUserInRole(model.UserName, "Driver"))
                {
                    return RedirectToAction("TestDriver", "Drivers");
                }
            }


          else
            {
                ModelState.AddModelError("", "Invalid username or password.");
           }
        }

        return View(model);
    }

一旦用户登录,我想根据他的角色将他重定向到不同的视图

尝试了网上的所有内容以及以前的帖子没有任何帮助

0 个答案:

没有答案