public class CheckAttribute : Attribute
{
private string _a ;
{
get { return _a; }
set { _a= value; }
}
public CheckAttribute(string a)
{
_a = a;
}
}
public class Check:Page // 取attribute值
{
protected override void OnInit(EventArgs e)
{
CheckPage();
base.OnInit(e);
}
private void CheckPage()
{
CheckAttribute att = (CheckAttribute)CheckAttribute.GetCustomAttribute(this.GetType(), typeof(CheckAttribute));
if (att != null)
{
if (!CheckPermission(att.a))
{
HttpContext.Current.Response.Redirect("aaa.aspx");
}
}
}
public bool CheckPermission(string a)//判断权限
{
if (a == "aa")
{
return true;
}
else { return false; }
}apsx页面:
[Check("aa")]
public partial class master_Default :Check
{
protected void Page_Load(object sender, EventArgs e)
{
}
public bool bind(string aa)
{ if (aa == "admin") { return true; } else return false; }
}