title: ASP.NET MVC - check authentification
body: <p>It is possible something like this in MVC, Razor?</p>
  
  <pre><code>@if (Request.IsAuthenticated)
  {
         &lt;span&gt;Welcome&amp;nbsp;&lt;/span&gt; &lt;strong&gt;@Html.Encode(User.Identity.Name)&lt;/strong&gt;
          @Html.ActionLink("Sign Out", "Out", "Login")
  }
  else
  {
         if (!@Request.Path.ToLower().Contains("login"))
         {
            return View("Login");
  
         }
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Ok! I found out the answer:</p>
  
  <pre><code> @if (Request.IsAuthenticated)
   {
         &lt;span&gt;Welcome&amp;nbsp;&lt;/span&gt; &lt;strong&gt;@Html.Encode(User.Identity.Name)&lt;/strong&gt;
          @Html.ActionLink("Sign Out", "Out", "Login")
   }
   else
   {
        if (!@Request.Path.ToLower().Contains("login"))
        {
  
           Response.Redirect("login");
  
         }
   }
  </code></pre>