Action属性,权限设定属性  
  [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class PurviewEnumAttribute : Attribute
{
public string PurviewString { get; set; } public PurviewEnumAttribute(string purview)
{
this.PurviewString = purview;
}
}
Action属性,权限验证属性

  [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class SuperICAuthorizeAttribute : AuthorizeAttribute
{
public string[] ActionPowers { get; set; } public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
string actionName = filterContext.ActionDescriptor.ActionName;
object[] attributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(PurviewEnumAttribute), true);
if (attributes != null && attributes.Count() > )
{
string power = (attributes[] as PurviewEnumAttribute).PurviewString;
this.ActionPowers = power.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
}
base.OnAuthorization(filterContext);
} protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
{
return false;
}
if (ActionPowers == null)
{
return true;
}
if (ActionPowers.Length == )
{
return true;
}
// if (ActionPowers.Any(httpContext.User.IsInRole))
if (ActionPowers.Any((new string[]{"","","",""}).Contains))
{
return true;
}
else
{
return false;
}
}
}

使用:Index需要权限为2的才能够进入,SuperICAuthorize过滤器中验证是否具有2的权限

[PurviewEnum("")]
[SuperICAuthorize]
public ActionResult Index()

MVC权限验证过滤器的更多相关文章

  1. NET MVC权限验证

    ASP.NET MVC权限验证 封装类 写该权限类主要目地 为了让权限配置更加的灵活,可以根据SQL.json.或者XML的方式来动态进行页面的访问控制,以及没有权限的相关跳转. 使用步骤 1.要建一 ...

  2. 在.Net MVC结构API接口中推断http头信息实现公共的权限验证过滤器演示样例

    //control   action public class TestController : ApiController { [MyAuthFilter] public string test(s ...

  3. ASP.NET MVC权限验证 封装类

    写该权限类主要目地 为了让权限配置更加的灵活,可以根据SQL.json.或者XML的方式来动态进行页面的访问控制,以及没有权限的相关跳转. 使用步骤 1.要建一个全局过滤器 //受权过滤器 publi ...

  4. C# MVC权限验证

    前言 之前一直没怎么接触过权限验证这块,刚好公司老平台改版,就有了这篇权限验证.此篇文章大致讲解下 精确到按钮级别的验证如何实现.以及权限验证设计的参考思路(菜鸟一枚,大神勿喷). 在开发大项目的时候 ...

  5. 关于filter web api mvc 权限验证 这里说的够详细了。。。

    参考:http://www.cnblogs.com/willick/p/3331520.html Filter(筛选器)是基于AOP(面向方面编程)的设计,它的作用是对MVC框架处理客户端请求注入额外 ...

  6. .net web mvc 权限验证

    这里分享MVC的权限验证,内容中可能存在一些,莫名其妙的方法,那些是以前封装好的,大致可以根据方法名称知道他的意思. using Game.Entity; using Game.Entity.Plat ...

  7. mvc 权限验证

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. mvc权限验证--AuthorizeAttribute

    在做后台管理时用户登录后就需要验证哪些权限了,没有登录的就直接退出到登录页面. 系统有自带的权限[Authorize],可用于几个地方: 1.将属性[Authorize]置于相关的action上方,验 ...

  9. MVC权限验证之ActionFilterAttribute

    参考:http://www.cnblogs.com/waitingfor/archive/2011/12/27/2303784.html ActionFilterAttribute是Action过滤类 ...

随机推荐

  1. 可替代google的各种搜索引擎

    http://www.aol.com http://www.duckduckgo.com http://www.gfsoso.com http://www.googlestable.com  http ...

  2. Linux怎样改动root用户的password

    Linux系统的root账号是很重要的一个账号.也是权限最大的一个账号,可是有时候忘了rootpassword怎么办?总不能重装系统吧,这个是下下策.事实上Linux系统中,假设忘记了root账号pa ...

  3. 直接插入排序(Straight Insertion Sort)

    直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. /* 对顺序表L作直接插入排序 */ void ...

  4. 深入理解cookie与session

    cookie和session是web开发比較基础也比較重要的知识,cookie和session用于用户的状态管理.简单的来说它们都仅仅是http中的一个配置项,在Servlet规范中也仅仅相应一个类而 ...

  5. hdoj--2036--改革春风吹满地(数学几何)

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  6. Laravel-数据库队列

    Laravel-数据库队列 标签(空格分隔): php 介绍 Laravel队列为不同的后台队列服务提供统一的API,例如Beanstalk,Amazon SQS, Redis,甚至其他基于关系型数据 ...

  7. 【DNN 系列】 模块开发 8.0.1

    1.创建第一个模块需要准备的东西有 https://github.com/dnnsoftware/DNN.Templates/releases/tag/1.0.1 VS 2015 插件 创建一个项目M ...

  8. c# window服务-初学习

    window服务-初学习 一.工具: VS2015+NET Framework4.5. 二.操作: 1.新建windows服务的项目: 2.修改windows服务相关内容: 3.预览windows服务 ...

  9. Map<String,String>转换json字符串

    import java.util.HashMap; import java.util.Map; import net.sf.json.JSONObject; public class testJson ...

  10. 为什么越来越少的开源项目使用 GPL 协议

    原文出处: opensource   译文出处:oschina/王练    前段时间,我在 RedMonk 上看到了一篇来自 Stephen O’Grady 的有趣推文,介绍了开源许可证目前的状态,以 ...