title: How to access HttpContext.Current.User custom attributes in the view
body: <p>I want to access some custom attributes in my view from a <code>User</code> object. I am implementing custom attributes for authentication and I am changing the <code>HttpContext.Current.User</code> inside of my global.asax.</p>
  
  <p>This is the <code>User</code> class</p>
  
  <pre><code>public class User : IPrincipal
  {
      ...
      public bool IsAdministrator =&gt; IsInRole(RolesConstants.GlobalAdministrator);
      ...
  }
  </code></pre>
  
  <p>Here is where I am setting it in my <code>Global.asax</code></p>
  
  <pre><code>    protected void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
      {
          ...
  
          var winUser = new User
          {
              EMail = user.Person.Email,
              FirstName = user.Person.FirstName,
              LastName = user.Person.LastName,
              Identity = wi,
              NetworkAccountName = user.UserName,
              UserId = user.UserName,
              Roles = userRoles,
          };
  
          HttpContext.Current.User = winUser;
      }
  </code></pre>
  
  <p>As an example how can I do something like this?</p>
  
  <pre><code>&lt;button type="button" visible="@User.IsAdministrator" id="btn"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>Since the <code>User</code> object is already accessible I don't want to pass in a <code>Model</code> or use a string in the view such as <code>@User.IsInRole("Admin")</code></p>
  
  <p>Edit: should I be making a custom type derive from <code>IPrinciple</code> and explose the types like this?</p>
  
  <pre><code>...
          IIdentity Identity { get; }
          bool IsInRole(string role);
          bool IsAdministrator;
  ...
  </code></pre>