阻止登录用户访问asp.net中的登录页面mvc 5
问题描述:
我一直在试图让我的登录页面无法访问到已经登录的用户。他们宁愿被重定向到他们的仪表板,除非他们没有登录。阻止登录用户访问asp.net中的登录页面mvc 5
我已经做了以下,他们都没有工作。任何人都有解决方案吗?
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
if (Request.IsAuthenticated)
{
RedirectToAction("Index", "Dashboard");
}
ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard");
return View();
}
这也太
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
if (User.Identity.IsAuthenticated)
{
RedirectToAction("Index", "Dashboard");
}
ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard");
return View();
}
任何指导将不胜感激。谢谢
答
对不起,我刚才观察到我省略了应该重定向用户的线路上的“返回”。
我已经补充说,现在可
这低于
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Dashboard");
}
ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard");
return View();
}
正确的代码