title: MVC custom roleprovider how to hook it up to HttpContext.Current.User.IsInRole("myrole")
body: <p>I have an MVC app and I wrote a custom roleprovider for it as shown:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using VectorCheck.Models;
  
  namespace VectorCheck.Security
  {
      public class MyRoleProvider : RoleProvider
      {
          private VectorCheckRepository&lt;User&gt; _repository { get; set; }
  
          public MyRoleProvider()
          {
              _repository = new VectorCheckRepository&lt;User&gt;();
          }
  
          public MyRoleProvider(VectorCheckRepository&lt;User&gt; repository)
          {
              _repository = repository;
          }
  
          public override void AddUsersToRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override string ApplicationName
          {
              get
              {
                  throw new NotImplementedException();
              }
              set
              {
                  throw new NotImplementedException();
              }
          }
  
          public override void CreateRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
          {
              throw new NotImplementedException();
          }
  
          public override string[] FindUsersInRole(string roleName, string usernameToMatch)
          {
              throw new NotImplementedException();
          }
  
          public override string[] GetAllRoles()
          {
              throw new NotImplementedException();
          }
  
          public override string[] GetRolesForUser(string username)
          {
              var user = _repository.GetUser(username);
  
              return new string[] { user.Role.Name };
          }
  
          public override string[] GetUsersInRole(string roleName)
          {
              throw new NotImplementedException();
          }
  
          public override bool IsUserInRole(string username, string roleName)
          {
              var user = _repository.GetUser(username);
  
              return string.Compare(user.Role.Name, roleName, true) == 0;
          }
  
          public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
          {
              throw new NotImplementedException();
          }
  
          public override bool RoleExists(string roleName)
          {
              throw new NotImplementedException();
          }
      }
  }
  </code></pre>
  
  <p>This works really well with restricting access to controllers and actions using:</p>
  
  <pre><code>[Authorize(Roles = "Administrator")]
  </code></pre>
  
  <p>above the controller or action.</p>
  
  <p>I also want restricted access to some things in the view though using:</p>
  
  <pre><code>HttpContext.Current.User.IsInRole("Administrator")
  </code></pre>
  
  <p>This method isn't part of my roleprovider though so isn't getting overridden.</p>
  
  <p>Does anyone know how to do it for this method as well?</p>