遇到这个需求,想到的第一点就是,这个肯定是需要写在一个通用的地方。方便调用。一般可以定义个 父类控制器在OnActionExcuting方法执行前写逻辑,先上代码,一边写代码一边讲解:

  /// <summary>
        /// 执行方法前
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.IsChildAction)
                return;

            //需要排除校验的控制器名称 
            string[] excludeControllerName = { "error", "ThirdPartyNotify" };
            bool hasElenemt = MyCommFun.StringHasElenemt(filterContext.Controller.ToString().ToLower(), excludeControllerName);
            if (hasElenemt)
            {   //排除error控制器
                return;
            }
       
            string userAgent = Request.UserAgent;
            //如果为微信端登录,则需要网页授权,排除error控制器
            if (userAgent.ToLower().IndexOf("micromessenger") > -1)
            {
                if (WebHelper.IsAjax())//判断是否为ajax请求的情况
                {
                   ProcessInvalidUser_Ajax(filterContext);
                    return;
                }
                else
                {
//网页授权 bool obpOk= OAuth2BaseProc(filterContext, wid); if (!obpOk) { return; } } } base.OnActionExecuting(filterContext); }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-11-18
  • 2022-03-02
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2021-12-26
  • 2021-11-22
  • 2021-08-02
相关资源
相似解决方案