コード例 #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            SessionID = filterContext.RequestContext.HttpContext.Request.Cookies["cydonSessionID"]?.Value ?? string.Empty;

            SessionCache sessionCache = Cache.GetCache <SessionCache>();

            if (filterContext.RequestContext.HttpContext.Request.QueryString.AllKeys.Contains("forceSessionRefresh"))
            {
                sessionCache.ForceRefreshSession(SessionID);
            }

            SessionCache.CachedSession cachedSession = sessionCache.GetSessionBySessionID(SessionID);

            object authorizationAttribute = GetType().GetCustomAttributes(typeof(CydonAuthorizationAttribute), true).FirstOrDefault();

            if (authorizationAttribute == null)
            {
                authorizationAttribute = filterContext.ActionDescriptor.GetCustomAttributes(typeof(CydonAuthorizationAttribute), true).FirstOrDefault();
            }

            if (authorizationAttribute == null)
            {
                if (cachedSession != null && cachedSession.Expiration >= DateTime.Now)
                {
                    UserID = cachedSession.UserID;
                }
                return;
            }

            if (cachedSession == null || cachedSession.Expiration < DateTime.Now)
            {
                string redirect = Config.INSTANCE.UnauthenticatedRedirect + "?redirectUrl=" + Uri.EscapeDataString(filterContext.RequestContext.HttpContext.Request.Url.ToString());
                filterContext.Result = Redirect(redirect);

                return;
            }

            UserID = cachedSession.UserID;

            cachedSession.ResetSessionExpiration();

            if (filterContext.Result == null)
            {
                PreActionCheck(filterContext, cachedSession);
            }
        }
コード例 #2
0
ファイル: CySysController.cs プロジェクト: CSX8600/Cydon
        public ActionResult RefreshSession()
        {
            var failed  = new { success = false };
            var success = new { success = true };

            if (SessionID == null)
            {
                return(Json(failed));
            }

            SessionCache sessionCache = Cache.GetCache <SessionCache>();

            SessionCache.CachedSession cachedSession = sessionCache.GetSessionBySessionID(SessionID);

            if (cachedSession == null || cachedSession.Expiration < DateTime.Now)
            {
                return(Json(failed));
            }

            cachedSession.ResetSessionExpiration();
            return(Json(success));
        }