title: How do I access Nancy's CurrentUser property from within a Razor view?
body: <p>I am trying to access the <code>CurrentUser</code> property of the <code>NancyContext</code>. How do I do this from within the html of a Razor view?</p>
  
  <p>I would be grateful for a code snippet if possible.</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I now extend <code>Nancy.ViewEngines.Razor.HtmlHelpers</code> to give me cross-view data with syntactic sugar that keeps the view code terse and readable. </p>
  
  <p>Here are a few examples:</p>
  
  <pre><code>public static bool IsRegistered&lt;T&gt;(this HtmlHelpers&lt;T&gt; html)
  {
      var user = GetUser(html);
      return user != null &amp;&amp; user.IsRegistered;
  }
  
  public static bool IsAuthenticated&lt;T&gt;(this HtmlHelpers&lt;T&gt; html)
  {
      return GetUser(html) != null;
  }
  
  public static User GetUser&lt;T&gt;(this HtmlHelpers&lt;T&gt; html)
  {
      return (User)html.RenderContext.Context.CurrentUser;
  }
  </code></pre>
  
  <p>And some razor code from a view. Here I am deciding to include the html for a Sign In popup (Foundation Reveal) only if the user is not currently authenticated - makes sense.</p>
  
  <pre><code>@if (!Html.IsAuthenticated())
  {
      Html.Partial("Reveals/SignInReveal");
  }  
  </code></pre>