本节主要讲解过滤器
Q78. 介绍下ASP.NET MVC中的 Filters(过滤器) 和 Attributes(特性)?
Ans. ASP.NET MVC 提供了一种简单的方式在action执行之前或之后注入一段代码或逻辑,它就是ASP.NET MVC attributes,通过在Controller或者Action上使用Attributes来修饰即可。可以自定义过滤器或特性通过实现ASP.NET
MVC filter 接口或继承并重载ASP.NET MVC filter attribute类。
通常,过滤器被用来执行以下常见的功能点:
Custom Authentication(自定义认证)
Custom Authorization (User based or Role based)(自定义授权-基于用户或角色)
Error handling or logging(异常处理或记录日志)
User Activity Logging(用户活动日志)
Data Caching(数据缓存)
Data Compression(数据比较)
Q79. 介绍下ASP.NET MVC中几种不同的Filters(过滤器) ?
Ans. 主要有以下五种类型Filters:
Authentication Filters(认证过滤器)
该过滤器是从ASP.NET MVC5中引入的。IAuthenticationFilter接口是用来创建自定义认证过滤器。IAuthenticationFilter定义如下:
public interface IAuthenticationFilter{ void OnAuthentication(AuthenticationContext filterContext); void OnAuthenticationChallenge(AuthenticationChallengeContext
filterContext);
}通过实现IAuthenticationFilter接口,即可实现自定义的认证过滤特性。
延伸阅读
- ssh框架 2016-09-30
- 阿里移动安全 [无线安全]玩转无线电——不安全的蓝牙锁 2017-07-26
- 消息队列NetMQ 原理分析4-Socket、Session、Option和Pipe 2024-03-26
- Selective Search for Object Recognition 论文笔记【图片目标分割】 2017-07-26
- 词向量-LRWE模型-更好地识别反义词同义词 2017-07-26
- 从栈不平衡问题 理解 calling convention 2017-07-26
- php imagemagick 处理 图片剪切、压缩、合并、插入文本、背景色透明 2017-07-26
- Swift实现JSON转Model - HandyJSON使用讲解 2017-07-26
- 阿里移动安全 Android端恶意锁屏勒索应用分析 2017-07-26
- 集合结合数据结构来看看(二) 2017-07-26
学习是年轻人改变自己的最好方式