public static void RefreshLoggedInUserSession(HttpSessionStateBase currentSession) { User currentUser = null; string username = LoggedInUserUsername(currentSession); if (username == null) { return; } using (var usersRepository = new UsersRepository(new MyTubeDBEntities())) { currentUser = usersRepository.GetUserByUsername(username); } if (currentUser == null) { currentSession.Abandon(); } else { var currentUserForSession = new UserSessionModel { Username = currentUser.Username, UserType = currentUser.UserType, Blocked = currentUser.Blocked }; currentSession.Add(loggedInUser, currentUserForSession); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; Services.User user = (Services.User)session[Constants.SESSION_USER]; if (user != null) { return; } String urlFrom = String.Empty; UrlHelper url; //send them off to the login page url = new UrlHelper(filterContext.RequestContext); urlFrom = filterContext.Controller.ControllerContext.RequestContext.HttpContext.Request.RawUrl; if (!String.IsNullOrEmpty(urlFrom)) { urlFrom = String.Format("?{0}", urlFrom); } var loginUrl = url.Content(String.Format("~/LogIn{0}", urlFrom)); session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.HttpContext.Response.StatusCode = 403; filterContext.HttpContext.Response.Redirect(loginUrl, false); filterContext.Result = new EmptyResult(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session["users"]; if (((user == null) && (!session.IsNewSession)) || (session.IsNewSession)) { session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "Controller", "Login" }, { "Action", "Index" } }); } else { System.Int32 timeOut = System.Web.HttpContext.Current.Session.Timeout; if (timeOut < 5) { session.Timeout = timeOut + 10; } } }
public void Abandon(string openId) { _log.Write("SessionPool.Abandon", "OpenId:" + openId, TraceEventType.Verbose); if (String.IsNullOrEmpty(openId)) { return; } HttpSessionStateBase session = _sessionTable[openId] as HttpSessionStateBase; if (session == null) { return; } session.Clear(); session.Abandon(); lock (_lockObj) { _sessionTable.Remove(openId); } _log.Write("SessionPool.Abandon Done", "OpenId:" + openId, TraceEventType.Verbose); }
public static void Logoff(HttpSessionStateBase session, HttpResponseBase response) { session.Abandon(); FormsAuthentication.SignOut(); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ""); cookie.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(cookie); }
public static void AbandonSession(HttpSessionStateBase session) { try { logger.Info(string.Format("Clearing session {0}.", session.SessionID)); ConfigurationHelper config = new ConfigurationHelper(); if (!config.IsMockUserIdentity) { session.Clear(); session.Abandon(); } } catch (Exception) { session.Clear(); session.Abandon(); } }
public static void AbandonAndRenewCookie(this HttpSessionStateBase session, HttpResponseBase response) { string prevSessionId = session.SessionID; session.Abandon(); var sessionStateSection = (SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState"); string sessionCookieName = sessionStateSection.CookieName; response.Cookies.Add(new HttpCookie(sessionCookieName, "")); response.Cookies.Add(new HttpCookie(PrevSessionIdCookieName, prevSessionId)); }
/// <summary> /// Clears the user session, clears the forms auth ticket, expires the forms auth cookie. /// </summary> /// <param name="session">HttpSessionStateBase</param> /// <param name="response">HttpResponseBase</param> public static void Logoff(HttpSessionStateBase session, HttpResponseBase response) { // Delete the user details from cache. session.Abandon(); // Delete the authentication ticket and sign out. FormsAuthentication.SignOut(); // Clear authentication cookie. HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ""); cookie.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(cookie); }
/// <summary> /// 权限错误,页面跳转处理 /// </summary> /// <param name="filterContext"></param> /// <param name="type"></param> public void TransferToPermissionDeniedPage(ActionExecutingContext filterContext, int type = 1) { ContentResult result = new ContentResult(); switch (type) { case 1: result.Content = "<script>window.location.href='/Home/LoginTimeout';</script>"; _session.RemoveAll(); _session.Abandon(); break; case 2: result.Content = "<script>window.location.href='/Home/NoPermission';</script>"; break; default: result.Content = "<script>window.location.href='/Home/Sorry';</script>"; _session.RemoveAll(); _session.Abandon(); break; } filterContext.Result = result; }
/// <summary> /// 安全退出系统 /// </summary> /// <param name="response">响应对象</param> /// <param name="session">session对象</param> public static void Logout(HttpResponseBase response, HttpSessionStateBase session) { FormsAuthentication.SignOut(); session.Abandon(); HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, string.Empty); cookie1.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(cookie1); HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); cookie2.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(cookie2); FormsAuthentication.RedirectToLoginPage(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session["Usr_ID"]; if (user == null) { //send them off to the login page var url = new UrlHelper(filterContext.RequestContext); var loginUrl = filterContext.RouteData.Values.ContainsValue("Admin") ? url.Content("~/Admin/Login") : url.Content("~/Home/Index"); session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session["User"]; if (((user == null) && (!session.IsNewSession)) || (session.IsNewSession)) { //send them off to the login page var url = new UrlHelper(filterContext.RequestContext); var loginUrl = url.Content("~/Account/LogIn"); session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public ActionResult LogOut() { HttpSessionStateBase session = HttpContext.Session; //filterContext.HttpContext.Session; if (session != null) { session.RemoveAll(); session.Clear(); session.Abandon(); Session["IsLogged"] = false; LoginInformation.UserInformation = null; LoginInformation.PermittedMenues = null; } return(Json(new { result = "Redirect", url = Url.Action("Index", "Home") })); }
public void FormsAuthenticationLogout(HttpSessionStateBase session, HttpResponseBase response) { FormsAuthentication.SignOut(); session.Abandon(); // clear authentication cookie HttpCookie formsAuthenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, ""); formsAuthenticationCookie.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(formsAuthenticationCookie); HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); cookie2.Expires = DateTime.Now.AddYears(-1); response.Cookies.Add(cookie2); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session["CurrentUserName"]; if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(DisableUserSessionAttribute), false).Any()) { return; } else if (((user == null) && (!session.IsNewSession)) || (session.IsNewSession)) { //send them off to the login page var url = new UrlHelper(filterContext.RequestContext); var loginUrl = url.Content("~/User/LogIn"); session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext != null) { HttpSessionStateBase objHttpSessionStateBase = filterContext.HttpContext.Session; var userSession = objHttpSessionStateBase["userObject"]; if (((userSession == null) && (!objHttpSessionStateBase.IsNewSession)) || (objHttpSessionStateBase.IsNewSession)) { objHttpSessionStateBase.RemoveAll(); objHttpSessionStateBase.Clear(); objHttpSessionStateBase.Abandon(); if (filterContext.HttpContext.Request.IsAjaxRequest()) { filterContext.HttpContext.Response.StatusCode = 403; filterContext.Result = new JsonResult { Data = "LogOut" }; } } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //do not execute the filter logic for Login/Index if (filterContext.RouteData.GetRequiredString("controller").Equals("LogIn", StringComparison.CurrentCultureIgnoreCase) && filterContext.RouteData.GetRequiredString("action").Equals("Index", StringComparison.CurrentCultureIgnoreCase)) { return; } HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session["User"]; if (((user == null) && (!session.IsNewSession)) || (session.IsNewSession)) { session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Login" }, { "action", "Index" } }); } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; if ((CheckSessionAlive == null) || (CheckSessionAlive(session))) { return; } var url = new UrlHelper(filterContext.RequestContext); var loginUrl = url.Content(LoginUrl); if (session != null) { session.RemoveAll(); session.Clear(); session.Abandon(); } filterContext.HttpContext.Response.StatusCode = 403; filterContext.HttpContext.Response.Redirect(loginUrl, true); filterContext.Result = new EmptyResult(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!NotVerifyMethod) { HttpSessionStateBase session = filterContext.HttpContext.Session; var user = session[Constantes.GrupoLocalizacion.UsuarioSesionId]; if (user == null) { session.RemoveAll(); session.Clear(); session.Abandon(); String vAccion = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString(); if (filterContext.HttpContext.Request.IsAjaxRequest()) { if (vAccion != "_Session_Terminada") { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Sistema" }, { "action", "_Session_Terminada" } } ); } } else { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Sistema" }, { "action", "Login" }, { "SessionExpired", "True" } } ); } } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; //var user = session["BrokerOfLoggedInUser"]; if ((session["LoggedInUser"] == null)) { if (GetUserLoggedIn(HttpContext.Current.User.Identity.GetUserId()) == 1) { //RestaurantEntities rce = new RestaurantEntities(); //tblRestaurantUser ru = new tblRestaurantUser(); ////brokerUserFactory = new BrokerUserFactory(); ////decimal membership_id = SessionManger.BrokerOfLoggedInUser(Session).membership_id; //string user_id = HttpContext.Current.User.Identity.GetUserId(); //int RestaurentId = Convert.ToInt32(session["RestaurantId"]); //ru.is_loggedIn = 0; //ru.UserId = user_id; //ru.Restaurant_id = RestaurentId; //rce.tblRestaurantUsers.Attach(ru); //var entry = rce.Entry(ru); //entry.State = EntityState.Modified; //rce.SaveChanges(); filterContext.HttpContext.GetOwinContext().Authentication.SignOut(); session.RemoveAll(); session.Clear(); session.Abandon(); } //send them off to the login page var url = new UrlHelper(filterContext.RequestContext); var loginUrl = url.Content("~/Account/Login"); filterContext.Result = new RedirectResult(loginUrl); return; } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { string loginUrl = System.Configuration.ConfigurationManager.AppSettings.Get("loginUrl"); logger.Info("FGL OnActionExecuting"); try { HttpSessionStateBase session1 = filterContext.HttpContext.Session; logger.Info("get session test:" + session1.SessionID.ToString()); HttpSessionStateBase session = filterContext.HttpContext.Session; if (filterContext.HttpContext.Session["UserID"] == null) { logger.Info("filterContext.HttpContext.Session[UserID] null"); var url = new UrlHelper(filterContext.RequestContext); //var loginUrl = url.Content("~/Account/Login"); session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.HttpContext.Response.Redirect(loginUrl, true); } else { logger.Info("filterContext.HttpContext.Session[UserID] not null"); } } catch (Exception e) { logger.Info(e.ToString()); var url = new UrlHelper(filterContext.RequestContext); //var loginUrl = url.Content("~/Account/Login"); filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public void AbandonHttpSession() { _httpSessionStateBase.Abandon(); }
public void SignOut(HttpSessionStateBase session) { formsAuthentication.SignOut(); session.Abandon(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { // Do not execute the filter logic for User/Login if (filterContext.RouteData.GetRequiredString("controller").Equals("User", StringComparison.CurrentCultureIgnoreCase) && filterContext.RouteData.GetRequiredString("action").Equals("Login", StringComparison.CurrentCultureIgnoreCase)) { if (!filterContext.HttpContext.Request.IsAjaxRequest()) { return; } else { filterContext.Result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { Valid = false, RedirectUrl = FormsAuthentication.LoginUrl } }; } } HttpSessionStateBase session = filterContext.HttpContext.Session; var username = HttpContext.Current.User != null ? HttpContext.Current.User.Identity.Name : string.Empty; _userFacade = new UserFacade(); _userFacade.CheckExceededMaxConcurrent(username, session); if (!filterContext.HttpContext.Request.IsAjaxRequest()) { if (((session["sessionid"] == null) && (!session.IsNewSession)) || (session.IsNewSession)) { // Clear cache var cacheKey = string.Format(CultureInfo.InvariantCulture, "{0}_user_info", username); if (HttpRuntime.Cache[cacheKey] != null) { HttpRuntime.Cache.Remove(cacheKey); } session.RemoveAll(); session.Clear(); session.Abandon(); string returnUrl = GetReturnUri(filterContext); RouteValueDictionary dict = new RouteValueDictionary(); dict.Add("controller", "User"); dict.Add("action", "Login"); if (!string.IsNullOrWhiteSpace(returnUrl)) { dict.Add("returnUrl", returnUrl); } filterContext.Result = new RedirectToRouteResult(dict); } base.OnActionExecuting(filterContext); } else { if (((session["sessionid"] == null) && (!session.IsNewSession)) || (session.IsNewSession)) { // Clear cache var cacheKey = string.Format(CultureInfo.InvariantCulture, "{0}_user_info", username); if (HttpRuntime.Cache[cacheKey] != null) { HttpRuntime.Cache.Remove(cacheKey); } session.RemoveAll(); session.Clear(); session.Abandon(); filterContext.Result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { Valid = false, RedirectUrl = FormsAuthentication.LoginUrl } }; } } }
public static void ClearSession(HttpSessionStateBase state) { state.Abandon(); }
public void Abandon() { _session.Abandon(); }