System.Collections.Generic;

[AttributeUsage(AttributeTargets.Class)]
public class Permissions : Attribute
{
    
public enum PermissionType
    {
        Admin,
        Consignor,
        SuperConsignor
    }

    
public Permissions(PermissionType[] pPermissionTypes)
    {
        
this.PermissionList = pPermissionTypes;
    }

    
public PermissionType[] PermissionList { getset; }
}
 PermissionCheckPage : Page
{
    protected override void OnPreLoad(System.EventArgs e)
    {
        
base.OnPreLoad(e);
        
foreach (Attribute a in this.GetType().GetCustomAttributes(true))
        {
            
if (a is Permissions)
            {
                Permissions ps 
= a as Permissions;
                
foreach (Permissions.PermissionType pt in ps.PermissionList)
                {
                    
switch (pt)
                    {
                        
case Permissions.PermissionType.Admin:
                            CheckPermission(
"IsAdmin");
                            
break;
                        
case Permissions.PermissionType.Consignor:
                            CheckPermission(
"IsConsignor");
                            
break;
                        
case Permissions.PermissionType.SuperConsignor:
                            CheckPermission(
"IsSuperConsignor");
                            
break;
                        
default:
                            
break;
                    }
                }
            }
        }
    }
    
private void CheckPermission(string input)
    {
        
if (Session[input] == null)
        {
            Response.Redirect(
"Index.aspx");
        }
        
else
        {
            
if (!Convert.ToBoolean(Session[input]))
            {
                Response.Redirect(
"Index.aspx");
            }
        }
    }
}
 System.Collections.Generic;

[Permissions(new Permissions.PermissionType[] { Permissions.PermissionType.Admin, Permissions.PermissionType.Consignor, Permissions.PermissionType.SuperConsignor })]
public partial class Default15 : PermissionCheckPage
{
    
protected void Page_Load(object sender, EventArgs e)
    {

    }
}

相关文章:

  • 2021-12-21
  • 2022-02-16
  • 2021-08-06
  • 2021-05-27
  • 2022-02-02
  • 2021-05-17
  • 2021-06-24
  • 2021-05-19
猜你喜欢
  • 2021-10-10
  • 2022-01-24
  • 2021-08-31
  • 2022-03-05
  • 2021-07-25
  • 2021-07-12
  • 2021-11-16
相关资源
相似解决方案