ASP.NET MVC - 检查身份验证

时间:2014-03-26 07:46:56

标签: asp.net-mvc authentication razor

在MVC,Razor中有可能是这样吗?

@if (Request.IsAuthenticated)
{
       <span>Welcome&nbsp;</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&nbsp;</span> <strong>@Html.Encode(User.Identity.Name)</strong>
        @Html.ActionLink("Sign Out", "Out", "Login")
 }
 else
 {
      if (!@Request.Path.ToLower().Contains("login"))
      {

         Response.Redirect("login");

       }
 }

0 个答案:

没有答案