在Asp.Net MVC项目中通过重写ActionFilterAttribute中的方法,我们就可以在轻松的在Action方法执行前后做一些特殊的操作如:[身份认证、日志记录、内容截取等]。

但是我们要想在OnResultExecuting\OnResultExecuted中获取Actioin返回的HTML该怎么做呢?

废话不多说先看代码如下:

运行结果如下:

微软官方的ActionFilterAttribute定义如下:

   using System;
namespace System.Web.Mvc
{
/// <summary>Represents the base class for filter attributes.</summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public abstract class ActionFilterAttribute : FilterAttribute, IActionFilter, IResultFilter
{
/// <summary>Called by the ASP.NET MVC framework before the action method executes.</summary>
/// <param name="filterContext">The filter context.</param>
public virtual void OnActionExecuting(ActionExecutingContext filterContext)
{
}
/// <summary>Called by the ASP.NET MVC framework after the action method executes.</summary>
/// <param name="filterContext">The filter context.</param>
public virtual void OnActionExecuted(ActionExecutedContext filterContext)
{
}
/// <summary>Called by the ASP.NET MVC framework before the action result executes.</summary>
/// <param name="filterContext">The filter context.</param>
public virtual void OnResultExecuting(ResultExecutingContext filterContext)
{
}
/// <summary>Called by the ASP.NET MVC framework after the action result executes.</summary>
/// <param name="filterContext">The filter context.</param>
public virtual void OnResultExecuted(ResultExecutedContext filterContext)
{
}
}
}

Asp.Net Mvc - 在OnResultExecut* 拦截Action返回的HTML的更多相关文章

  1. asp.net mvc 使用Ajax调用Action 返回数据【转】

      使用asp.net mvc 调用Action方法很简单. 一.无参数方法. 1.首先,引入jquery-1.5.1.min.js 脚本,根据版本不同大家自行选择. <script src=& ...

  2. Asp.Net MVC 利用ReflectedActionDescriptor判断Action返回类型

    System.Web.Mvc.ReflectedActionDescriptor descriptor = filterContext.ActionDescriptor as System.Web.M ...

  3. asp.net mvc @Html.Partial @Html.Action @Html.RenderPartial @Html.RenderAction区别

    转载自 :  <asp.net mvc @Html.Partial @Html.Action @Html.RenderPartial @Html.RenderAction区别> 先复制过来 ...

  4. [转]ASP.NET MVC 入门9、Action Filter 与 内置的Filter实现(介绍)

    有时候你想在调用action方法之前或者action方法之后处理一些逻辑,为了支持这个,ASP.NET MVC允许你创建action过滤器.Action过滤器是自定义的Attributes,用来标记添 ...

  5. ASP.NET MVC 入门9、Action Filter 与 内置的Filter实现(介绍)

    原帖地址:http://www.cnblogs.com/QLeelulu/archive/2008/10/09/1307660.html 有时候你想在调用action方法之前或者action方法之后处 ...

  6. 走入asp.net mvc不归路:[5]Action的返回

    asp.net mvc提供了多种返回方式,一方面使得视图可以重用,另一方面灵活强大,有直接返回视图,返回Json,返回文件流,返回到相同Controller的Action,返回到另一个Controll ...

  7. ASP.NET MVC 异常Exception拦截器Fillter

    异常信息的处理在程序中非常重要, 在asp.net mvc中提供异常属性拦截器进行对异常信息的处理,异常拦截器也没有什么的,只是写一个类,继承另一个类(System.Web.Mvc.FilterAtt ...

  8. ASP.NET MVC 异常Exception拦截

    一.前言 由于客户端的环境不一致,有可能会造成我们预计不到的异常错误,所以在项目中,友好的异常信息提示,是非常重要的.在asp.net mvc中实现异常属性拦截也非常简单,只需要继承另一个类(Syst ...

  9. 在asp.net mvc模式中使用PartialView返回部分HTML

    PartialView(返回HTML(局部)) 在asp.net mvc中返回View时使用的是ViewResult,它继承自ViewResultBase 同时它还有个兄弟PartialViewRes ...

随机推荐

  1. 一个表的两个列连接另外一个表的一个列SQL语句怎么写

    f619424517 | 浏览 2207 次 推荐于2016-09-09 11:38:18   最佳答案   select a.flightid,a.flightname,b.cityname,c.c ...

  2. Mina学习之Codec Filter

    为何要使用Codec Filter 1. 任何一个网络应用程序接受到消息后,都需要知道消息的开头和结束. 2. 你可以把协议解析的部分放在IoHandler,但这样就会造成业务代码和协议解析代码混淆在 ...

  3. 移动开发框架,第【一】弹:QuoJs 官方文档(汉化版)

    作者:一只猿 原文地址: http://www.92ez.com 转载请注明出处,谢谢 帮助说明 如果您认为QuoJS只是一个触摸事件管理器,那你就错了,它是一个功能丰富的类库,无需第三方JavaSc ...

  4. hdu1558--并查集+判断线段相交

    简单的计算几何题,判断两线段是否相交.将相交的两线段使用并查集归到一类中.查询时输出线段对应集合中元素的个数. #include<stdio.h> struct Point{ double ...

  5. codechef Turbo Sort 题解

    Input t – the number of numbers in list, then t lines follow [t <= 10^6].  Each line contains one ...

  6. JAVA基于AE调用GP实现泰森多边形

    调用GP实现数据处理是较快捷.较易入手的方法. 使用JAVA语言基于AE调用GP实现泰森多边形的代码例如以下: public void CreatVoronoi(){ try { GeoProcess ...

  7. hdu5294||2015多校联合第一场1007 最短路+最大流

    http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...

  8. 使用vi是方向键变乱码 退格键不能使用的解决方法

    一.编辑/etc/vim/vimrc.tiny 由于/etc/vim/vimrc.tiny的拥有者是root用户,所以要在root的权限下对这个文件进行修改.很简单,这个文件里面的倒数第二句话是“se ...

  9. MyBatis Tutorial – CRUD Operations and Mapping Relationships – Part 1---- reference

    http://www.javacodegeeks.com/2012/11/mybatis-tutorial-crud-operations-and-mapping-relationships-part ...

  10. 使用AVCaptureSession显示相机预览

    #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface ViewController ...