当前位置: 首页 > news >正文

网站如何不被百度搜到微信小程序彻底清除数据

网站如何不被百度搜到,微信小程序彻底清除数据,wordpress怎么设置广告位,互联网行业推广员资格证明图片asp.net MVC 权限设计一文中没有demo放出来,应大家的要求#xff0c;这里补充上文并放出demo。 几点说明#xff1a; 1、基于将角色与controller、action相关联来判断用户是否有权 2、通过自定义AuthorizeAttribute实现 3、demo 仅供参考#xff0c;一些规则可以根据实际情况… asp.net MVC 权限设计一文中没有demo放出来,应大家的要求这里补充上文并放出demo。   几点说明       1、基于将角色与controller、action相关联来判断用户是否有权     2、通过自定义AuthorizeAttribute实现     3、demo 仅供参考一些规则可以根据实际情况重新定义   简明需求 1、可以对每个action实现权限控制并且可以在数据库动态配置 2、权限分为允许所有人访问、允许注册用户访问、允许\禁止特定角色人访问   数据库设计   在demo里不使用数据库这里给出表对应的类 /// /// 控制器和Action/// public class ControllerAction{public int Id{get;set;}public string Name{get;set;}/// /// IsController是指是否是controller如果为false/// 表示是action那么controllerName字段就派上用场了/// public bool IsController{get;set;}/// /// 控制器名称/// 如果IsController为false该项不能为空/// public string ControllName{get;set;}/// /// 是指是否允许没有权限的人访问 /// public bool IsAllowedNoneRoles{get;set;}/// /// 是否允许有角色的人访问 /// public bool IsAllowedAllRoles{get;set;}}/// /// 用户与角色的关联表/// public class ControllerActionRole{public int Id{get;set;}/// /// 对应的ControllerAction编号/// public int ControllerActioId{get;set;}/// /// 对应的角色编号/// public int RoleId{get;set;}/// /// IsAllowed表示包含RoleId的用户是否有权限访问ControllerActioId/// public bool IsAllowed{get;set;}}/// /// 角色/// public class Role{public int Id{get;set;}public string Name{get;set;}public string Description{get;set;}}/// /// 用户/// public class User{public int Id{get;set;}public string Name{get;set;}}/// /// 用户与角色的关联表/// public class UserRole{public int Id{get;set;}public int UserId{get;set;}public int RoleId{get;set;}} 核心流程   我们见一个Database类来模拟数据库 /// /// /// 模拟数据库/// public class Database{public static List Users;public static List Roles;public static List UserRoles;public static List ControllerActions;public static List ControllerActionRoles;static Database(){// 初始化用户Users new List(){new User(){Id1,NameAdmin},new User(){Id2,Name User},new User(){Id3,NameGuest}};Roles new List(){new Role() {Id1,NameAdministrator},new Role() {Id2,NameUser}};UserRoles new List(){new UserRole(){Id1,RoleId1,UserId1}, //管理员new UserRole(){Id2,RoleId2,UserId2} //用户};ControllerActions new List(){new ControllerAction(){Id1,NameIndex,IsControllertrue,IsAllowedNoneRolestrue,IsAllowedAllRolestrue}, // /Home 允许所有人访问new ControllerAction(){Id2,ControllNameHome,NameAdmin,IsControllerfalse,IsAllowedNoneRolesfalse,IsAllowedAllRoles false}, // /Home/Admin 管理员才能访问new ControllerAction(){Id3,ControllNameHome,NameUser,IsControllerfalse,IsAllowedNoneRolesfalse,IsAllowedAllRoles true}, // /Home/User 有角色的人才能访问new ControllerAction(){Id4,ControllNameHome,NameUserOnly,IsControllerfalse,IsAllowedNoneRolesfalse,IsAllowedAllRoles false}, // /Home/UserOnly 用户才能访问};ControllerActionRoles new List() { new ControllerActionRole(){ Id1,ControllerActioId 2,RoleId 1,IsAllowed true }, // 管理员才能访问new ControllerActionRole(){ Id2,ControllerActioId 4,RoleId 2,IsAllowed true } // USER才能访问};}} 来看我们的主要代码 /// /// 自定义AuthorizeAttribute/// public class UserAuthorizeAttribute : AuthorizeAttribute{public override void OnAuthorization(AuthorizationContext filterContext){var user filterContext.HttpContext.Session[CurrentUser] as User;// 用户为空赋予Guestif (user null){user Database.Users.Find(u u.Name Guest);}var controller filterContext.RouteData.Values[controller].ToString();var action filterContext.RouteData.Values[action].ToString();var isAllowed this.IsAllowed(user, controller, action);if (!isAllowed){filterContext.RequestContext.HttpContext.Response.Write(无权访问);filterContext.RequestContext.HttpContext.Response.End();}}/// /// 判断是否允许访问/// ///  用户///  控制器///  action/// 是否允许访问public bool IsAllowed(User user, string controller, string action){// 找controllerActionvar controllerAction Database.ControllerActions.Find(ca ca.IsController false ca.Name action ca.ControllName controller);//action无记录找controllerif (controllerAction null){controllerAction Database.ControllerActions.Find(ca ca.IsController ca.Name controller);}// 无规则if (controllerAction null){return true;}// 允许没有角色的也就是说允许所有人包括没有登录的用户 if (controllerAction.IsAllowedNoneRoles){return true;}// 允许所有角色只要有角色就可以访问 if (controllerAction.IsAllowedAllRoles){var roles Database.UserRoles.FindAll(ur ur.UserId user.Id);if (roles.Count 0){return true;}else{return false;}}// 选出action对应的角色 var actionRoles Database.ControllerActionRoles.FindAll(ca ca.ControllerActioId controllerAction.Id).ToList();if (actionRoles.Count 0){// 角色数量为0也就是说没有定义访问规则默认允许访问 return true;}var userHavedRolesids Database.UserRoles.FindAll(ur ur.UserId user.Id).Select(ca ca.RoleId).ToList();// 查找禁止的角色 var notAllowedRoles actionRoles.FindAll(r !r.IsAllowed).Select(ca ca.RoleId).ToList();if (notAllowedRoles.Count 0){foreach (int roleId in notAllowedRoles){// 用户的角色在禁止访问列表中不允许访问 if (userHavedRolesids.Contains(roleId)){return false;}}}// 查找允许访问的角色列表 var allowRoles actionRoles.FindAll(r r.IsAllowed).Select(ca ca.RoleId).ToList();if (allowRoles.Count 0){foreach (int roleId in allowRoles){// 用户的角色在访问的角色列表 if (userHavedRolesids.Contains(roleId)){return true;}}}// 默认禁止访问return false;}} 测试 [HandleError][UserAuthorize]public class HomeController : Controller{public ActionResult Index(){ViewData[Message] 欢迎使用 ASP.NET MVC!;return View();}public ActionResult Admin(){ViewData[Message] 只有管理员才能访问!;return View(Index);}public ActionResult User(){ViewData[Message] 只要是注册用户就能访问!;return View(Index);}public ActionResult UserOnly(){ViewData[Message] 只能是User才能能访问!;return View(Index);}public ActionResult Login(string user){Session[CurrentUser] Database.Users.Find(u u.Name user);if (Session[CurrentUser] ! null){ViewData[Message] 你已登录为 user;}return View(Index);}public ActionResult About(){return View();}}   1、登录为Admin   访问Admin   访问User   访问UserOnly   2、登录为User   访问Admin   访问User 访问UserOnly   demo下载 MVCRole.rar 转载于:https://www.cnblogs.com/xiaoqi/archive/2011/01/24/1942880.html
http://www.zqtcl.cn/news/399825/

相关文章:

  • 介绍做网站的标题在线图片编辑器好用吗
  • 金华建设网站公司笔记本销售网站开发的背景
  • 国外做的好看的网站设计网络营销推广方案怎么做
  • 网站建站业务wordpress网站域名地址
  • 烟台网站制作这做菠菜网站
  • 网站建设vr百度站长
  • 织梦网站广告代码如何写网页设计你若安好便是晴天作业
  • 网站建设 上海wordpress 知更鸟 公告
  • 建小说网站需要多少钱罗湖区住房和建设网站
  • 湖南专业网站建设服务做网站的底图尺寸多大
  • 山东省住房与建设厅网站首页有名的wordpress主题商
  • 常州市金坛区网站建设毕业设计代做淘宝好还是网站好
  • 品牌网站建设营销型网站设计网站整合方案
  • 网站开发设计师网站代理什么意思
  • 网站层级关系邯郸品牌商标vi设计策划公司
  • 网站开发产品需求说明小网站代码
  • 苏州网站推广排名网站建设方案范文8篇
  • 自己做考试题目网站广州番禺区美食攻略
  • 广州做网站如何如何制作一个网页
  • 网站定制开发收费标准是多少网站代码优化方案
  • 制作卡牌的网站深圳正规煤气公司
  • 手表网站哪家好网站用图片
  • 群辉nas 做网站wordpress linux 中文
  • 平面设计素材网站排名巩义网站建设方案表
  • 延庆网站制作搜索引擎优化的基础是什么
  • 管理手机网站商城网站备案流程
  • 怀化买房网站网站广告js代码添加
  • 做网站 帮别人卖服务器wordpress主题多页面
  • 代理游戏网站潍坊市建设工程管理处网站
  • 大同推广型网站建设网站规划建设与管理维护第二版答案