zoukankan      html  css  js  c++  java
  • mvc filter 的用法

    1、建个类在model里面名字随便

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using RHRSP.Web.Controllers.Common;
    
    namespace RHRSP.Web.Models
    {
        public class DemoActionAttributeFilter : ActionFilterAttribute
        {
            public string Message { get; set; }
    
            public override void OnActionExecuted(ActionExecutedContext filterContext)
            { //在Action执行之后执行 输出到输出流中文字:After Action Excute xxx
               // filterContext.HttpContext.Response.Write(@"<br />After Action Excute" + "\t " + Message);
              //  base.OnActionExecuted(filterContext);
               
            }
    
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            { //在Action执行前执行
                //filterContext.HttpContext.Response.Write(@"<br />Before Action Excute" + "\t " + Message);
                //base.OnActionExecuting(filterContext);
                     
            }
    
            public override void OnResultExecuted(ResultExecutedContext filterContext)
            { //在Result执行之后 
               // filterContext.HttpContext.Response.Write(@"<br />After ViewResult Excute" + "\t " + Message);
               // base.OnResultExecuted(filterContext);              
            }
    
            public override void OnResultExecuting(ResultExecutingContext filterContext)
            { //在Result执行之前
               // filterContext.HttpContext.Response.Write(@"<br />Before ViewResult Excute" + "\t " + Message);
               // base.OnResultExecuting(filterContext);
            }
    
        }
    }
    

    2、要在哪个controller触发。就把该filter特性写在上面,如:

     [DemoActionAttributeFilter(Message = "action")]
        public class IndexController : Controller
        {
    

    3、这样就可以用了,调用action前,后,调用result前,后。顺序把注释去掉就可以实验了

  • 相关阅读:
    excel导入phpmyadmin
    Python 教程资源
    SAE部署Python-让云端自动运行Python代码
    python socket 超时设置 errno10054
    使用python一步一步搭建微信公众平台(一)
    PHP读取MySQL数据
    php连接mysql并读取数据
    php分页例子实现读取mysql数据分页显示
    51Nod1305 Pairwise Sum and Divide
    SPOJ SUBXOR
  • 原文地址:https://www.cnblogs.com/wdw31210/p/2506136.html
Copyright © 2011-2022 走看看