1. 程式人生 > >利用RBAC模型實現一個通用的許可權管理系統

利用RBAC模型實現一個通用的許可權管理系統

複製程式碼
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class PowerAttribute : LoginAttribute
    {
        /// <summary> 訪問許可權驗證 </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            LoginAttribute loginAttribute 
= new LoginAttribute(); loginAttribute.OnActionExecuting(filterContext); var routeAction = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"] + "." +
HttpContext.Current.Request.RequestContext.RouteData.Values["Action"]; List
<Menu> userOwnMenuList = MenuService.GetUserOwnMenuList().ResultModel as List<Menu> ?? new List<Menu>(); var isHavepermission = userOwnMenuList.FirstOrDefault(m => m.ControllerAction.ToLower() == routeAction.ToLower()) != null; if (!isHavepermission) { HttpContext.Current.Response.Write(
"您沒有許可權訪問"); HttpContext.Current.Response.End(); } } }
複製程式碼