Custom Role Authorization, MVC

  1. using System.Web.Mvc;  
  2.   
  3. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultipe = true)]  
  4. public class ComponentViewer : AuthorizeAttribute  
  5. {  
  6.       
  7.     private static IEnumerable<string> RoleList = new string[]{  
  8.             "Role1",  
  9.             "Role2",  
  10.             "Role3"  
  11.         };  
  12.       
  13.     private static string RoleValue = String.Join(ROLE_DELIMITER,RoleList);  
  14.       
  15.     private const string ROLE_DELIMITER = ",";  
  16.       
  17.     public ComponentViewer()  
  18.     {  
  19.         Roles = RoleList;  
  20.     }  
  21.       
  22.     public static IEnumerable<string> ComponentViewerRoles  
  23.     {  
  24.         get  
  25.         {  
  26.             return RoleList;  
  27.         }  
  28.     }  
  29. }