如何将用户重定向到mvc中的登录页面
How to redirect a user to login page in mvc
我的默认页面是主页,但我想将用户重定向到登录页面,如果他没有登录。我在部分视图中尝试了以下但失败了
@if (Request.IsAuthenticated)
{
<div>Welcone</div>
}
else
{
@Html.ActionLink("Login", "Login", "Account")
}
Kartikeya Khosla 的回答对我有用。我是这样做的
public ActionResult Index()
{
if (Request.IsAuthenticated)
{
return View();
}
else
{
return RedirectToAction("Login", "Account");
}
}
我的默认页面是主页,但我想将用户重定向到登录页面,如果他没有登录。我在部分视图中尝试了以下但失败了
@if (Request.IsAuthenticated)
{
<div>Welcone</div>
}
else
{
@Html.ActionLink("Login", "Login", "Account")
}
Kartikeya Khosla 的回答对我有用。我是这样做的
public ActionResult Index()
{
if (Request.IsAuthenticated)
{
return View();
}
else
{
return RedirectToAction("Login", "Account");
}
}