1.controller

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6.  
  7. namespace TestMvc.Controllers
  8. {
  9. public class HomeController : Controller
  10. {
  11. [CustomFilter]
  12. [ResultFilter]
  13. public ActionResult Index()
  14. {
  15. ViewBag.Title = "Home Page";
  16. //throw new Exception("");
  17. return View();
  18. }
  19. }
  20. }

 2.filters

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Web.Mvc;
  7.  
  8. namespace TestMvc
  9. {
  10. public class CustomFilter : ActionFilterAttribute
  11. {
  12. public override void OnActionExecuted(ActionExecutedContext filterContext)
  13. {
  14. base.OnActionExecuted(filterContext);
  15. }
  16.  
  17. public override void OnActionExecuting(ActionExecutingContext filterContext)
  18. {
  19. base.OnActionExecuting(filterContext);
  20. }
  21. }
  22.  
  23. public class ExFilter : IExceptionFilter
  24. {
  25. public void OnException(ExceptionContext filterContext)
  26. {
  27. // throw new NotImplementedException();
  28. }
  29. }
  30.  
  31. public class ResultFilter : ActionFilterAttribute,IResultFilter
  32. {
  33. public override void OnResultExecuted(ResultExecutedContext filterContext)
  34. {
  35. throw new NotImplementedException();
  36. }
  37.  
  38. public override void OnResultExecuting(ResultExecutingContext filterContext)
  39. {
  40. throw new NotImplementedException();
  41. }
  42. }
  43. }

 3.global filter

  1. using System.Web;
  2. using System.Web.Mvc;
  3.  
  4. namespace TestMvc
  5. {
  6. public class FilterConfig
  7. {
  8. public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  9. {
  10. filters.Add(new ExFilter());
  11. filters.Add(new HandleErrorAttribute());
  12. }
  13. }
  14. }

  

mvc filters的更多相关文章

  1. ASP.NET MVC Filters 4种默认过滤器的使用【附示例】 数据库常见死锁原因及处理 .NET源码中的链表 多线程下C#如何保证线程安全? .net实现支付宝在线支付 彻头彻尾理解单例模式与多线程 App.Config详解及读写操作 判断客户端是iOS还是Android,判断是不是在微信浏览器打开

    ASP.NET MVC Filters 4种默认过滤器的使用[附示例]   过滤器(Filters)的出现使得我们可以在ASP.NET MVC程序里更好的控制浏览器请求过来的URL,不是每个请求都会响 ...

  2. System.Web.Mvc.Filters.IAuthenticationFilter.cs

    ylbtech-System.Web.Mvc.Filters.IAuthenticationFilter.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Cultu ...

  3. ASP.NET MVC Filters 4种默认过滤器的使用【附示例】

    过滤器(Filters)的出现使得我们可以在ASP.NET MVC程序里更好的控制浏览器请求过来的URL,不是每个请求都会响应内容,只响应特定内容给那些有特定权限的用户,过滤器理论上有以下功能: 判断 ...

  4. mvc Filters 过滤器

    项目需要控制controller和action的访问权限. 看了下资料,发觉还是很方便的. 首先在mvc项目下创建一个文件夹 Filters, 然后在Filters中创建一个类.代码如下 namesp ...

  5. Understanding ASP.NET MVC Filters and Attributes

    这篇文章把Asp.net MVC的filter介绍的很详细,值得收藏. http://www.dotnet-tricks.com/Tutorial/mvc/b11a280114-Understandi ...

  6. .net core MVC Filters 过滤器介绍

    一.过滤器的优级依次介绍如下(逐次递减): Authorization Filter ->  Resource Filter -> Acton Filter -> Exception ...

  7. ASP.NET Core 中文文档 第四章 MVC(4.3)过滤器

    原文:Filters 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:何镇汐 ASP.NET MVC 过滤器 可在执行管道的前后特定阶段执行代码.过滤器可以配置为全局有效.仅对控 ...

  8. 实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器

    MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过App_Start中的FilterConfig来实现的过滤器注册是全局的,也就是整个应用程序都会使用的,针对单独的Fi ...

  9. EF和MVC系列文章导航:EF Code First、DbContext、MVC

    对于之前一直使用webForm服务器控件.手写ado.net操作数据库的同学,突然来了EF和MVC,好多新概念泉涌而出,的确犹如当头一棒不知所措.本系列文章可以帮助新手入门并熟练使用EF和MVC,有了 ...

随机推荐

  1. Freemaker基于word模板动态导出汇总整理

    Freemaker基于word模板动态导出汇总整理 一.使用的jar包: 二.Word模板动态导出的基本思路: 1.首先通过自己在word中创建好需要导出的word文本+表格的模板,模板中需要填写内容 ...

  2. thinkcmf5 iis+php重写配置

    TP在本机运行非常好,谁想到服务器上后,连http://www.***.com/wap/login/index都404错误了, 中间的郁闷过程不表. 解决方案分两步: 第一步: 下载rewrite_2 ...

  3. python模块之collections模块

    计数器 Counter 计数元素迭代器 elements() 计数对象拷贝 copy() 计数对象清空 clear() from collections import Counter #import ...

  4. HDU_6194 后缀数组+RMQ

    好绝望的..想了五个多小时,最后还是没A...赛后看了下后缀数组瞬间就有了思路...不过因为太菜,想了将近两个小时才吧这个题干掉. 首先,应当认为,后缀数组的定义是,某字符串S的所有后缀按照字典序有小 ...

  5. SSRS 制作报表时报错: 超时时间已到。在操作完成之前超时时间已过或服务器未响应。

    转载注明出处,原文地址:http://www.cnblogs.com/zzry/p/5718739.html  在用ssrs 制作报表时报如下错误 错误信息截图: 看到如上错误第一个想到的解决方法就是 ...

  6. java多线程的常用方法

    介绍一些多线程中的常用方法: //启动方法 a.start(); //返回代码正在被哪个线程调用的信息 a.currentThread(); //返回线程的名字 a.currentThread().g ...

  7. leetcode 【 Remove Duplicates from Sorted Array II 】python 实现

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  8. 使用charles进行https抓包

    一.charles电脑端设置 1.在Charles的菜单栏上选择"Proxy"->"Proxy Settings",填入代理端口8888(这个端口不一定填 ...

  9. mvc-自定义Route

    public class CustomerRoute : RouteBase { //从路径中解析出controller.action以及其他参数,创建RouteData(其中包括HttpHandle ...

  10. 基数排序(java实现)

    基数排序  就是先比较数组中元素的个位数,排序得到新的数组,然后比较新的数组中的十位数,排序得到新数组,然后再对最新得到的数组比较百位数.......依次循环 比如{82 ,31 ,29 ,71, 7 ...