mvc 权限验证
2024-09-21 01:24:37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PaiXie.Core;
using Newtonsoft.Json;
using PaiXie.Utils;
using PaiXie.Bll;
namespace PaiXie.Pos.Admin {
/// <summary>
/// 权限控制
/// </summary>
public class MvcMenuFilter : ActionFilterAttribute { #region 权限控制 private bool _isEnable = true; public MvcMenuFilter() {
_isEnable = true;
} public MvcMenuFilter(bool IsEnable) {
_isEnable = IsEnable;
} public override void OnActionExecuting(ActionExecutingContext filterContext) { try {
//默认true 执行验证
if (_isEnable) {
var route = filterContext.RouteData.Values;
string area = filterContext.RouteData.DataTokens["area"].ToString();
var url = string.Format("/{0}/{1}/{2}", area, route["controller"], route["action"]);
//没有权限
if (!new Users().IsAuth(url)) {
//if (_isEnable) {
BaseResult BaseResult = new BaseResult();
BaseResult.result = -99;
BaseResult.message = "没有权限!";
string str = JsonConvert.SerializeObject(BaseResult, Formatting.Indented);
ContentResult ContentResult = new ContentResult();
ContentResult.Content = str;
filterContext.Result = ContentResult;
//}
}
}
}
catch (Exception ex) { PlanLog.WriteLog(ex.ToString(), "MvcMenuFilter"); }
base.OnActionExecuting(filterContext);
}
#endregion
}
}
最新文章
- C++: DataGridView::DataSource
- Java 8 Lambda表达式探险
- CobarClient源码分析(1)
- 查看SqlServer的内存使用情况
- nyoj 119 士兵杀敌(三)(RMQ)
- .NET 进程和线程
- [翻译][MVC 5 + EF 6] 7:加载相关数据
- Python队列服务 Python RQ Functions from the __main__ module cannot be processed by workers.
- HTML基础(2) 格式标签 文本标签
- calling c++ from golang with swig--windows dll(一)
- LinkedHashMap:我还能实现LRU
- 对象序列化 输入输出流概念 InputOutStream OutputStream
- [BZOJ1031] [JSOI2007] 字符加密Cipher (后缀数组)
- 学习ASP.NET Core Razor 编程系列二——添加一个实体
- ES6常用特性总览
- .NET Core中延迟单例另一种写法【.NET Core和.NET Framework的beforefieldinit差异】
- layui前端框架
- 菜鸟入门【ASP.NET Core】9:RoutingMiddleware介绍以及MVC引入
- .NET拾忆:EventLog(Windows事件日志监控)
- 微擎 人人商城 merchant.php源码
热门文章
- UiTextField 限制输入长度
- 牛客网-《剑指offer》-跳台阶
- 微信小程序 - 动态背景图片实现
- C++ 第六课:C/C++关键字及其用法
- 算法笔记_229:有理数的循环节(Java)
- selenium快速跳转视图到指定元素
- MySQL事物系列:3:innodb_flush_log_at_trx_commit小实验
- 使用 loop device 制作安装镜像
- Android——碎片事务调用失败
- Multitenant Architecture---PDB与CDB