Sachin Singh

Sachin Singh

  • 7
  • 55.8k
  • 81.1k

Custom Role provider vs Custom Authorize attribute.

Jul 16 2020 12:11 PM
we can set Principle while creating our Custom authorizing attribute like
  1. public class BasicAuthenticationAttribute : AuthorizationFilterAttribute  
  2. {  
  3.    //todo  
  4.    IPrincipal principal = new GenericPrincipal(identity, UserDetails.Roles.Split(','));  
  5. }  
and we can also create CustomRoleProvider like below
  1. public class UserRoleProvider : RoleProvider    
  2. {     
  3.         public override string[] GetRolesForUser(string username)    
  4.         {    
  5.             using (EmployeeContext _Context=new EmployeeContext())    
  6.             {    
  7.                 var userRoles =  //todo  
  8.                 return userRoles;    
  9.             }                 
  10.         }   
  11.     }    
  12. }
My question is what is the difference between the two and when to use one over another or both are same?

Answers (1)