Esempio n. 1
0
        public RedirectResult Remove(string id)
        {
            try
            {
                var webSession = new WebSession(Configuration, Context, Logger);

                if (!string.IsNullOrEmpty(id))
                {
                    var result = webSession.FindWebSessionId(id);

                    if (result != null)
                    {
                        webSession.DeleteWebSession(result);
                    }
                }

                return(Redirect("~/WebSession"));
            }
            catch (Exception e)
            {
                Log.Logger.Error("HttpGet SendSms: " + e.Message);
                return(Redirect("~/WebSession"));
            }
        }
Esempio n. 2
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            try
            {
                var webSession = new WebSession(Configuration, Context, Logger);

                IpRemote = CommonHelper.GetIp(Request);

                var userId = context.HttpContext.User.GetSubjectId();

                var logOut = string.IsNullOrEmpty(userId);


                var userInfo = UserManager.GetUserAsync(context.HttpContext.User);

                if (userInfo.Result == null)
                {
                    logOut = true;
                }
                else
                {
                    if (userId != null && !userId.Equals(userInfo.Result.Id))
                    {
                        logOut = true;
                    }
                }


                var sessionId = CommonHelper.GetCookie(Request, Const.CookieSessionId);


                if (string.IsNullOrEmpty(sessionId))
                {
                    logOut = true;
                }
                else
                {
                    var session = webSession.FindWebSessionId(sessionId);

                    if (session == null)
                    {
                        logOut = true;
                    }
                }


                if (!logOut)
                {
                    return;
                }
                _signInManager?.SignOutAsync();

                _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));

                context.Result = new RedirectResult("~/Account/Login");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }