title: Custom RoleProvider failing when AuthorizeAttribute applied with role
body: <p>I'm having an issue with a custom role provider in ASP.net MVC4. I implemented a very light weight RoleProvider which seems to work fine right up until I change</p>
  
  <pre><code>[Authorize]
  public class BlahController:....
  }
  </code></pre>
  
  <p>to</p>
  
  <pre><code>[Authorize(Roles="Administrator")]
  public class BlahController:....
  }
  </code></pre>
  
  <p>as soon as I make that change users are no longer authenticated and I get 401 errors. This is odd because my RoleProvider basically returns true for IsUSerInRole and a list containing "Administrator" for GetUserRoles.  I had breakpoints in place on every method in my custom RoleProvider and found that none of them were being called. </p>
  
  <p>Next I implemented my own authorize attribute which inherited from AuthorizeAttribute. In this I put in break points so I could see what was going on. It turned out that User.IsInRole(), which is called by the underlying attribute was returning false. </p>
  
  <p>I am confident that the role provider is properly set up. I have this in my config file</p>
  
  <pre><code>&lt;roleManager enabled="true" defaultProvider="SimplicityRoleProvider"&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name="SimplicityRoleProvider" type="Simplicity.Authentication.SimplicityRoleProvider" applicationName="Simplicity" /&gt;
    &lt;/providers&gt;
  &lt;/roleManager&gt;
  </code></pre>
  
  <p>and checking which role provider is the current one using the method described here: <a href="https://stackoverflow.com/questions/4976215/reference-current-roleprovider-instance">Reference current RoleProvider instance?</a> yields the correct result. However User.IsInRole persists in returning false. </p>
  
  <p>I am using Azure Access Control Services but I don't see how that would be incompatible with a custom role provider. </p>
  
  <p>What can I do to correct the IPrincipal User such that IsInRole returns the value from my custom RoleProvider?</p>
  
  <hr>
  
  <p>RoleProvider source:</p>
  
  <p>public class SimplicityRoleProvider : RoleProvider
      {
          private ILog log { get; set; }</p>
  
  <pre><code>    public SimplicityRoleProvider()
      {
          log = LogManager.GetLogger("ff");
      }        
  
      public override void AddUsersToRoles(string[] usernames, string[] roleNames)
      {
          log.Warn(usernames);
          log.Warn(roleNames);
      }
  
      public override string ApplicationName
      {
          get
          {
              return "Simplicity";
          }
          set
          {
  
          }
      }
  
      public override void CreateRole(string roleName)
      {
  
      }
  
      public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
      {
          return true;
      }
  
      public override string[] FindUsersInRole(string roleName, string usernameToMatch)
      {
          log.Warn(roleName);
          log.Warn(usernameToMatch);
          return new string[0];
      }
  
      public override string[] GetAllRoles()
      {
          log.Warn("all roles");
          return new string[0];
      }
  
      public override string[] GetRolesForUser(string username)
      {
          log.Warn(username);
          return new String[] { "Administrator" };
      }
  
      public override string[] GetUsersInRole(string roleName)
      {
          log.Warn(roleName);
          return new string[0];
      }
  
      public override bool IsUserInRole(string username, string roleName)
      {
          log.Warn(username);
          log.Warn(roleName);
          return true;
      }
  
      public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
      {
  
      }
  
      public override bool RoleExists(string roleName)
      {
          log.Warn(roleName);
          return true;
      }
  }
  </code></pre>