首页 > Web开发 > 详细

MVC项目后台管理,各页面判断登陆问题。

时间:2015-05-13 14:36:53      阅读:267      评论:0      收藏:0      [点我收藏+]
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;
        }
 
    }

 

MVC项目后台管理,各页面判断登陆问题。

原文:http://www.cnblogs.com/tinya/p/4500259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!