• 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();
    
            }
        }
    }
    

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

  • 相关阅读:
    linux shell执行远程计算机上的命令或者脚本(ssh)
    人到中年,愿我们的人生无悔
    资料
    新博客
    移植ok6410
    pm剩余要看的内容
    kernel boot
    regulator
    pm
    bochs安装一系列问题
  • 原文地址:https://www.cnblogs.com/ProDoctor/p/6056206.html
Copyright © 2020-2023  润新知