//解析特性 public class AdmCheckLevel : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { Type type = this.GetType(); var attribute = type.GetCustomAttributes(typeof(CheckLevelAttribute), false); for (int i = 0; i < attribute.Length; i++) { //设置属性 CheckLevelAttribute checklog = (CheckLevelAttribute)attribute[i]; //检查登录 if (AdminHelper.CheckLogin()) { filterContext.Result = Content(ErrorChinese.GetErrorInfoCHN(ErrorInfo.NotLogin).ToString()); return; } //判断权限 if (!new BllHelper().CheckALevel((long)AdminHelper.GetSession(), checklog.Level, WebHelper.GetMyDB)) { filterContext.Result = Content(ErrorChinese.GetAPowerInfoCHN(AdmPowerInfo.AdmInfoManager).ToString()); return; } } }
//创建特性
[AttributeUsage(AttributeTargets.Class)] public class CheckLevelAttribute : Attribute { public AdmPowerInfo Level { get; set; } public CheckLevelAttribute(AdmPowerInfo level) { this.Level = level; } }
时间: 2024-11-09 04:36:07