public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
            {
                IFormsAuthenticationService FormsService = new FormsAuthenticationService();
                SessionHelper session = new SessionHelper(filterContext.HttpContext);

                if (session.SessionEndTime == null)
                    session.SessionEndTime = DateTime.Now;
                else if (DateTime.Now - session.SessionEndTime > TimeSpan.FromMinutes(1))
                {
                    FormsService.SignOut();
                    filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { controller = "Account", action = "Logon" }));
                }
            }
        }
示例#2
0
        protected override void Execute(System.Web.Routing.RequestContext requestContext)
        {
            Session = new SessionHelper(requestContext.HttpContext);

            if (!requestContext.HttpContext.Request.Url.AbsoluteUri.ToLower().Contains("service"))
            {

                if (requestContext.HttpContext.Request.IsAuthenticated)
                {
                    IFormsAuthenticationService FormsService = new FormsAuthenticationService();

                    if (DateTime.Now - Session.SessionEndTime > TimeSpan.FromMinutes(20))
                    {
                        FormsService.SignOut();
                        requestContext.HttpContext.Response.Redirect(requestContext.HttpContext.Request.Url.AbsoluteUri, true);
                    }
                    else
                    {
                        Session.SessionEndTime = DateTime.Now;
                    }
                }
            }

            base.Execute(requestContext);
        }