コード例 #1
0
ファイル: ControllerHelper.cs プロジェクト: yuyu2you/X_NET40
        public static ActionResult NoPermission(this ControllerBase controller, NoPermissionException ex)
        {
            var ctx = controller.ControllerContext.HttpContext;
            var res = ctx.Request.Url.AbsolutePath;
#endif
            var pm  = ex.Permission;
            var msg = "无权访问数据[{0}],没有该数据的 {1} 权限".F(res, pm.GetDescription());

            LogProvider.Provider.WriteLog("访问", "拒绝", msg);

            var menu = ctx.Items["CurrentMenu"] as IMenu;

            var vr = new ViewResult()
            {
                ViewName = "NoPermission"
            };

#if __CORE__
            vr.ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(),
                                                 controller.ModelState)
            {
                ["Resource"]   = res,
                ["Permission"] = pm,
                ["Menu"]       = menu
            };
#else
            vr.ViewBag.Resource   = res;
            vr.ViewBag.Permission = pm;
            vr.ViewBag.Menu       = menu;
#endif
            return(vr);
        }
コード例 #2
0
        ///// <summary>无权访问</summary>
        ///// <param name="controller"></param>
        ///// <param name="action"></param>
        ///// <param name="pm"></param>
        ///// <returns></returns>
        //public static ActionResult NoPermission(this Controller controller, String action, PermissionFlags pm)
        //{
        //    var res = "[{0}/{1}]".F(controller.GetType().Name.TrimEnd("Controller"), action);
        //    var msg = "访问资源 {0} 需要 {1} 权限".F(res, pm.GetDescription());
        //    LogProvider.Provider.WriteLog("访问", "拒绝", msg);

        //    var ctx = controller.HttpContext;
        //    var menu = ctx.Items["CurrentMenu"] as IMenu;

        //    var vr = new ViewResult()
        //    {
        //        ViewName = "NoPermission"
        //    };
        //    vr.ViewData = controller.ViewData;
        //    vr.ViewData["Resource"] = res;
        //    vr.ViewData["Permission"] = pm;
        //    vr.ViewData["Menu"] = menu;

        //    return vr;
        //}

        /// <summary>无权访问</summary>
        /// <param name="actionContext"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static ActionResult NoPermission(this ActionContext actionContext, NoPermissionException ex)
        {
            var ctx = actionContext.HttpContext;
            var res = ctx.Request.GetEncodedUrl();
            var pm  = ex.Permission;
            var msg = "无权访问数据[{0}],没有该数据的 {1} 权限".F(res, pm.GetDescription());

            LogProvider.Provider.WriteLog("访问", "拒绝", msg);

            var menu = ctx.Items["CurrentMenu"] as IMenu;

            var vr = new ViewResult()
            {
                ViewName = "NoPermission"
            };

            vr.ViewData = new Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary(new EmptyModelMetadataProvider(),
                                                                                       actionContext.ModelState)
            {
                ["Resource"]   = res,
                ["Permission"] = pm,
                ["Menu"]       = menu
            };

            return(vr);
        }
コード例 #3
0
ファイル: ControllerHelper.cs プロジェクト: LX0/X_NET40
        /// <summary>无权访问</summary>
        /// <param name="controller"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static ActionResult NoPermission(this ControllerBase controller, NoPermissionException ex)
        {
            var ctx = controller.ControllerContext.HttpContext;
            var res = ctx.Request.Url.AbsolutePath;
            var pm  = ex.Permission;
            var msg = "无权访问数据[{0}],没有该数据的 {1} 权限".F(res, pm.GetDescription());

            LogProvider.Provider.WriteLog("访问", "拒绝", msg);

            var menu = ctx.Items["CurrentMenu"] as IMenu;

            var vr = new ViewResult()
            {
                ViewName = "NoPermission"
            };

            vr.ViewBag.Resource   = res;
            vr.ViewBag.Permission = pm;
            vr.ViewBag.Menu       = menu;

            return(vr);
        }
コード例 #4
0
ファイル: ControllerHelper.cs プロジェクト: yuyu2you/X_NET40
        /// <summary>无权访问</summary>
        /// <param name="controller"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
#if __CORE__
        public static ActionResult NoPermission(this ActionContext controller, NoPermissionException ex)
        {
            var ctx = controller.HttpContext;
            var res = ctx.Request.GetEncodedUrl();