zoukankan      html  css  js  c++  java
  • 过滤器

    1. 四种过滤器(面向切面编程)。

    (1)Action过滤器、Result过滤器、AuthorizationFilter过滤器、Exception过滤器;

    (2)执行先后顺序:AuthorizationFilter->Action->Result;

    (3)Exception过滤器为全局过滤器;

    2. Action过滤器(加载Action方法前后调用)的用法

    (1)处理当前方法的过滤器;

    (2)处理当前类的过滤器;

    (3)全局过滤器;

    3. Result过滤器:加载View视图前后调用。

    4. filterContext上下文对象

    (1)Route中保存了当前请求的路由信息和路由对象,如果本次请求是请求了某个区域里的控制方法,还可以通过 filterContext.RouteData.DataTokens["area"] 获取区域名称。

    //string strAction = filterContext.RouteData.Values["action"].ToString();

    string strController = filterContext.RouteData.Values["controller"].ToString();

    string strArea = filterContext.RouteData.DataTokens["area"].ToString();

    (2)另一种方式获取请求的类名的方法名

    string strAction2 = filterContext.ActionDescriptor.ActionName;

    string strController2=

    filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

    (3)检查被请求方法是否加了MoneyAttribute特性(可以用作权限验证操作等)

    if (filterContext.ActionDescriptor.IsDefined(typeof(Filters.MoneyAttribute), false))

                {

                    filterContext.Result = new ContentResult { Content="跳过!"};

                }

    5. AuthorizationFilter过滤器(授权过滤器)

    *请求管道事件注册方法机制:方法命名规则,Application_ResolveRequestCache(Application_事件名称),请求管道自动将该方法注册到该事件。

    Global.asax的使用。

    6. Exception过滤器(全局异常处理类)

  • 相关阅读:
    oracle——笔记——DDL语句
    Oracle中exp,imp的使用详解
    File类的简单使用
    理解Java的IO 流
    MyEclipse反编译Class文件的实现
    程序算法与人生选择
    Oracle 11g服务器与客户端卸载、安装
    Oracle字符集的查看查询和Oracle字符集的设置修改
    Java 对象的序列化 (Serializable)和反序列化
    Oracle创建表空间、创建用户以及授权、查看权限
  • 原文地址:https://www.cnblogs.com/HuoAA/p/4139250.html
Copyright © 2011-2022 走看看