title: MVC3 Razor Engine execution/rendering order
body: <p>I have a few links (login, logout, and register) in the _layout template, where the links are shown depending on whether the user is logged in. Like so:</p>
  
  <pre><code>if (User.Identity.IsAuthenticated)
  {
      &lt;span class="username"&gt;@User.Identity.Name&lt;/span&gt;
      &lt;span class="link"&gt;@Html.ActionLink("Logout", "Logout", "Account")&lt;/span&gt;
  }
  else
  {
      &lt;span class="link"&gt;@Html.ActionLink("Login", "Login", "Account")&lt;/span&gt;
      &lt;span class="link"&gt;@Html.ActionLink("Register", "Register", "Account")&lt;/span&gt;
  }
  </code></pre>
  
  <p>Problem is that the logout link is still displayed the first time the user logs out of the system (I would expect that to be immediately replaced with the login, and register links) - that is until the page is refreshed, or the user moves to another page. Here is the logout action code:</p>
  
  <pre><code>public ActionResult Logout()
  {
      FormsAuthentication.SignOut();
      Session.Abandon();
  
      return View();
  }
  </code></pre>
  
  <p>I have gone through this link - <a href="http://mvcdev.com/differences-between-asp-net-razor-and-web-forms-view-engines/" rel="nofollow">http://mvcdev.com/differences-between-asp-net-razor-and-web-forms-view-engines/</a> - which explains the execution order of the Razor engine, but in my case it seems to be executing differently. Ideally I would expect the FormsAuthentication.SignOut() to execute before the User.Identity.IsAuthenticated in the _layout. </p>
  
  <p>What am I doing wrong? Thanks!</p>