// validates user's guid then refreshes user's ttl
        public bool ValidateUser(Guid guid)
        {
            bool userIsValid = false;

            lock (syncRoot)
            {
                if (ActiveUsers.ContainsKey(guid))
                {
                    userIsValid = true;
                    ActiveUsers.RefreshUser(guid);
                }
            }
            return(userIsValid);
        }
Exemplo n.º 2
0
        private static void HandelActiveUserSession(ActionExecutingContext filterContext, BaseController controller)
        {
            var controllerValue = filterContext.RequestContext.RouteData.Values["controller"].ToString().ToLower();
            var actionValue     = filterContext.RequestContext.RouteData.Values["action"].ToString().ToLower();

            if (HttpContext.Current.Session != null)
            {
                if (HttpContext.Current.Session.IsNewSession)
                {
                    string cookieHeader = filterContext.HttpContext.Request.Headers["Cookie"];
                    if ((cookieHeader != null) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                    {
                        if (filterContext.HttpContext.Request.IsAuthenticated)
                        {
                            if (ActiveUsers.Count > 0 && !string.IsNullOrEmpty(controller.CurrentUserId))
                            {
                                ActiveUsers.Remove(controller.CurrentUserId);
                            }

                            filterContext.HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                            filterContext.HttpContext.Session["WelcomeMessage"] = null;
                            filterContext.Result = new RedirectResult("/Account/Login");
                        }
                    }
                }
                else if (filterContext.HttpContext.Request.IsAuthenticated && !string.IsNullOrEmpty(controller.CurrentUserId) && !ActiveUsers.ContainsKey(controller.CurrentUserId))
                {
                    var blPerson = new BLPerson();
                    var person   = blPerson.GetPersonByUserId(controller.CurrentUserId);
                    ActiveUsers.Add(controller.CurrentUserId, person);
                }
            }

            if (actionValue.ToLower() == "tabclosed" || actionValue.ToLower() == "logoff")
            {
                if (ActiveUsers.Count > 0 && !string.IsNullOrEmpty(controller.CurrentUserId))
                {
                    ActiveUsers.Remove(controller.CurrentUserId);
                }
            }
        }