zoukankan      html  css  js  c++  java
  • MVC 行为过滤器

    using FilterExam.Fiter;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;


    namespace FilterExam.Controllers
    {
        public class HelloController : Controller
        {
            [MyAction] 
            [MyResult]

            // GET: Hello
            public ActionResult Index()
            {
                Response.Write("行为执行中<br>");
                return View();
            }
        }
    }

    //行为过滤器

    在行为被执行前、后执行的过滤器
    重写方法OnActionExecuting(行为执行前)
    重写方法OnActionExecuted(行为执行后)


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;


    namespace FilterExam.Fiter
    {
        public class MyAction:ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {            
                filterContext.HttpContext.Response.Write("ing<br>");
            }


            public override void OnActionExecuted(ActionExecutedContext filterContext)
            {           
                filterContext.HttpContext.Response.Write("ed<br>");
            }
        }

    }


    //结果过滤器

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;


    namespace FilterExam.Fiter
    {
        public class MyResult:ActionFilterAttribute
        {
            public override void OnResultExecuting(ResultExecutingContext filterContext)
            {
                filterContext.HttpContext.Response.Write("结果执行前<br>");
            }


            public override void OnResultExecuted(ResultExecutedContext filterContext)
            {
                filterContext.HttpContext.Response.Write("结果执行后<br>");


            }
        }

    }


    ing
    行为执行中
    ed
    结果执行前

    Hello

    结果执行后
  • 相关阅读:
    Delphi Variant 通用类型[3] 流 Stream的相互转换
    Delphi System单元 Utf8ToAnsi、AnsiToUtf8、Utf8Decode、Utf8Encode、Utf8ToUnicode、UnicodeToUtf8 转换
    OCR (Optical Character Recognition,光学字符识别)
    使用Python写Windows Service服务程序
    双精度张量内核加快了高性能计算
    A100计算能力
    A100 Tensor核心可加速HPC
    A100 GPU硬件架构
    NVIDIA深度架构
    稀疏性如何为AI推理增加难度
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434745.html
Copyright © 2011-2022 走看看