在MVC,Razor中有可能是这样吗?
@if (Request.IsAuthenticated)
{
<span>Welcome </span> <strong>@Html.Encode(User.Identity.Name)</strong>
@Html.ActionLink("Sign Out", "Out", "Login")
}
else
{
if (!@Request.Path.ToLower().Contains("login"))
{
return View("Login");
}
}
编辑:
确定!我找到了答案:
@if (Request.IsAuthenticated)
{
<span>Welcome </span> <strong>@Html.Encode(User.Identity.Name)</strong>
@Html.ActionLink("Sign Out", "Out", "Login")
}
else
{
if (!@Request.Path.ToLower().Contains("login"))
{
Response.Redirect("login");
}
}