登录后重定向mvc5

时间:2017-10-21 00:06:13

标签: asp.net-mvc

在MVC中,在编写项目时,它会编写登录方案,登录屏幕和注册表,以及所有内容。

我创建了管理页面,但在您转到页面之前,如果我还没有创建cookie,请将登录页面发送给我。登录后我想这样做。登录后我不知道如何重定向到管理页面。

在构建项目时,您拥有编写viewbag.retutnurl的代码,但我不知道控制器是什么。

现在我不确定价值的来源。

如果有人确切知道并完成了,请告知。

2 个答案:

答案 0 :(得分:0)

您可以尝试以下两种方式中的任何一种来处理它。

public ActionResult Index() {
     return RedirectToAction("AdminAction");
     //Or you can try this
     return RedirectToAction("whateverAction", "whateverController");
}

答案 1 :(得分:0)

在默认生成的方法中,更改登录成功时执行的第一个case,并在此处添加自定义重定向,如下所示:

switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToAction("Index", "Admin", null); // new code
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
                case SignInStatus.Failure:
                default:
                    // If the user does not have an account, then prompt the user to create an account
                    ViewBag.ReturnUrl = returnUrl;
                    ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                    return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
            }

在您的管理类中,您应该放置[Authorize]数据注释

//admin controller
 [Authorize]
 public ActionResult Index()
        {

            return View();
        }