1
我想逃避登录页面,如果用户已经通过身份验证,所以我按照this question提供的建议。然后我得到了这个redirect过多的问题。当我第一次尝试登录时,即使我已成功登录,但出现此错误。除了第一次它作为魅力。我是MVC的新手。我搜查了一遍,发现了一些完全相同的情况,但他们没有为我工作,所以在这里我要求你的帮助。提前致谢 。重定向时重定向如果通过身份验证MVC 5
这是我的用户后,主页登录成功。(Home controller
)
[Authorize]
public ActionResult Main()
{
return View();
}
这是我的登录控制器动作。
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
if (Request.IsAuthenticated)
{
return RedirectToAction("Main", "Home");
}
return View();
}
我正在使用表单身份验证进行登录。
的web.config
<system.web>
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
<authentication mode="Forms">
<forms loginUrl="~/" defaultUrl="~/Login/Login">
</forms>
</authentication>
</system.web>
感谢您的建议,但它没有解决我的问题。 – jigyasu