zoukankan      html  css  js  c++  java
  • C# mvc统一通道使用过滤器

    问题描述

    使用C#过滤器有一个最大的问题就是在过滤器转向后程序仍然会执行方法体

    问题解决思路

    使用统一通道执行方法 不直接进入控制器 通过反射调用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Web;
    using System.Web.Mvc;
    
    namespace WebApplication2.Controllers
    {
        public class DefaultController : Controller
        {
            bool filter = true;
            protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                 filter = false;
                 Type t = typeof(DefaultController);
                 MethodInfo mf = t.GetMethod("Index");
                 mf.Invoke(this,null);
              
            }
            // GET: Default
            public ActionResult Index()
            {
                //Response.Write("我就是我");
                //Response.Flush();
                return View();
    
            }
        }
    }
    

      对于反射调用方法可使用缓存进行优化

  • 相关阅读:
    leetcode-String to Integer (atoi)
    2014薪水
    Ubunt下的软件集
    ubuntu常用软件
    python模块安装
    ubuntu下玩三国杀
    递归函数
    匿名函数
    装饰器函数
    生成器
  • 原文地址:https://www.cnblogs.com/ProDoctor/p/6056206.html
Copyright © 2011-2022 走看看