码迷,mamicode.com
首页 > Web开发 > 详细

ASP.Net 创建自定义类特效进行权限验证

时间:2016-04-20 13:15:11      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

//解析特性

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;
        }
    }

  

ASP.Net 创建自定义类特效进行权限验证

标签:

原文地址:http://www.cnblogs.com/Darkon/p/5412109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!