zoukankan      html  css  js  c++  java
  • 在执行Action之间检验是否登录

    在执行Action之间检验是否登录,也可以在执行Action前先执行某一个操作
     
    public class BaseController : Controller
        {
            protected string hostUrl = "";
            /// <summary>
            /// Action执行前判断
            /// </summary>
            /// <param name="filterContext"></param>
            protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                // url
                this.hostUrl = "http://" + this.Request.Url.Host;
                this.hostUrl += this.Request.Url.Port.ToString() == "80" ? "" : ":" + this.Request.Url.Port;
                this.hostUrl += this.Request.ApplicationPath;
     
                if (!this.checkLogin())// 判断是否登录
                {
                    filterContext.Result = RedirectToRoute("Default",new{ Controller = "Login", Action = "Index" });
                }
     
                base.OnActionExecuting(filterContext);
     
            }
     
     
            /// <summary>
            /// 判断是否登录
            /// </summary>
            protected bool checkLogin()
            {
                if (this.Session["userinfo"] == null)
                {
                    return false;
                }
                return true;
            }
     
        }
  • 相关阅读:
    docker基础总结
    python基础学习总结
    静默(命令行)安装oracle 11g
    java中如果函数return可能抛出异常怎么办
    Android 开发先驱的博客列表
    栈与队列
    线性表
    算法
    数据结构概论
    iOS开发中实现手势解锁
  • 原文地址:https://www.cnblogs.com/xiangzhong/p/5051277.html
Copyright © 2011-2022 走看看