title: ASP.NET Windows Authentication - Block user after some unsucceful login tries attempts
body: <p>So, I want to block users from access a website after some unsuccessful login attempts with windows authentication. I already implemented that authentication and to block them, I thought about using a custom role provider.</p>
  <p>My problem is that I get stuck in the GetRolesForUser method (no other method is reached) no matter if the user belongs to that role or not, which makes me think that the user is always unauthorized.</p>
  <p>Here's my code:</p>
  <pre><code>public class Auth : RoleProvider{
      
          public override string ApplicationName { get =&gt; throw new NotImplementedException(); set =&gt; throw new NotImplementedException(); }
  
  
          //other not implemented stuff
  
  
          public override string[] GetRolesForUser(string username)
          {
              PrincipalContext domainctx = new PrincipalContext(ContextType.Machine, null);
              UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domainctx, IdentityType.SamAccountName, username);
  
              return userPrincipal.GetGroups().Select(g =&gt; g.Name).ToArray(); 
              //breakpoint always stops the line above
              //it is returing the right roles tho
          }  
  
          public override bool IsUserInRole(string username, string roleName)
          {
              PrincipalContext domainctx = new PrincipalContext(ContextType.Machine, null);
              UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domainctx, IdentityType.SamAccountName, username);
  
              return userPrincipal.IsMemberOf(domainctx, IdentityType.Name, roleName);
          }
  }
  </code></pre>
  <p>Can you spot any problem here?
  Also, am I going in the right direction to block a user's access?
  Thanks!!</p>