mvc 权限控制
2016-01-08 15:11
204 查看
PriceComparison.Entity代码
Role类
PermissionsInRoles类
Authorization验证类
Controller控制类
Role类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations.Schema; namespace Test.Entity { public class Role { public int ID { get; set; } public string RoleName { get; set; } public bool IsDeleted { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } [NotMapped] public string PermissionDetail { get; set; } } public enum Authority { None = 0, Dashboard = 1, MatchManagement = 2, MatchCategory = 3, MatchProduct = 4, MatchServiceSwitch = 11, StandardProduct = 5, BrandManagement = 6, RetailerManagement = 7, CategoryManagement = 8, CombinedCategory = 9, RetailerCombinedCategory = 10 } }
PermissionsInRoles类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test.Entity { public class PermissionsInRoles { public long ID { get; set; } public int RoleID { get; set; } public int FunctionModelID { get; set; } public bool IsVisible { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } } }
Authorization验证类
using PriceComparison.Entity; using PriceComparison.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Test.Web.App_Start { public static class Authorization { public static void CheckAuthority(int functionModelID) { PCContext db = new PCContext(); User model = System.Web.HttpContext.Current.Session["CurrentUser"] as User; int count = db.PermissionsInRoles.Where(obj => obj.RoleID == model.RoleID && obj.FunctionModelID == functionModelID).Count(); if (count <= 0) { System.Web.HttpContext.Current.Response.Redirect("/Admin/User/AuthorityError"); } } } }
Controller控制类
using System; using System.Web; using System.Web.Mvc; namespace Test.Web.Areas.Admin.Controllers { public class CategoryController : Controller { public ActionResult Index() { Authorization.CheckAuthority((int)Authority.CategoryManagement); return View(); } public ActionResult CombinedCategory() { Authorization.CheckAuthority((int)Authority.CategoryManagement); return View(); } public ActionResult CategoryList() { Authorization.CheckAuthority((int)Authority.CategoryManagement); return View(); } public ActionResult CategoryPictureManage() { Authorization.CheckAuthority((int)Authority.CategoryManagement); return View(); } public ActionResult CombinedCategorysOfRetailer(long id) { Authorization.CheckAuthority((int)Authority.CategoryManagement); ViewBag.RetailerID = id; return View(); } public ActionResult RetailerCombinedCategory() { Authorization.CheckAuthority((int)Authority.CategoryManagement); return View(); } } }
相关文章推荐
- 华为机试——选秀节目打分
- 字符串匹配算法
- iOS:json格式字符串转字典,字典转json格式字符串
- JavaScript基本概念(五)---语句和函数
- React Native探索(六)不止是UI:React的使用场景探索
- 金融IC卡 ARQC和ARPC计算方法和实例
- jquery获取自定义的标签属性的值
- SpringMvc 开发配置流程
- RNN训练过程详解
- redis监控工具-redis sentinel使用说明及注意事项
- C#运用存储过程新增一条记录并返回自动生成的ID
- UVa1151 Buy or Build
- 教程网大全
- linux定时任务
- smarty基础指南
- 移动web相关touch事件触发(touchstart/touchmove/touchend)
- android 开发安全简单想法
- 计算机基本概念之字符编码,字符集
- Python之数据聚合与分组运算
- iOS 时间戳转换为字符串