Esempio n. 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var token = "";

            //Token by QueryString
            var request = filterContext.HttpContext.Request;

            if (request.QueryString[Token] != null)
            {
                token = request.QueryString[Token];
                var cookie = new HttpCookie(Token, token)
                {
                    Expires = DateTime.Now.AddDays(10)
                };
                filterContext.HttpContext.Response.Cookies.Add(cookie);
            }
            else if (request.Cookies[Token] != null)  //从Cookie读取Token
            {
                token = request.Cookies[Token].Value;
            }

            if (string.IsNullOrEmpty(token))
            {
                //直接登录
                filterContext.Result = LoginResult("");
                return;
            }
            else
            {
                //验证
                if (AuthUtil.CheckLogin(token, request.RawUrl) == false)
                {
                    //会话丢失,跳转到登录页面
                    filterContext.Result = LoginResult("");
                    return;
                }
            }

            base.OnActionExecuting(filterContext);
        }
Esempio n. 2
0
 public SSOController(AuthUtil authUtil)
 {
     _authUtil = authUtil;
 }