Here is an example:
protected void Session_Start(Object sender, EventArgs e) { //Check if there is a cookie from when the session started. //If not, the session has not been started yet, //so add the cookie. HttpContext context = HttpContext.Current; HttpCookieCollection cookies = context.Request.Cookies; HttpCookie SessionCookie = cookies["SessionStarted"]; if (SessionCookie == null) { HttpCookie cookie = new HttpCookie("SessionStarted", DateTime.Now.ToString()); cookie.Path = "/"; context.Response.Cookies.Add(cookie); } else { //If there was a cookie, but we are in this method starting a session //Then the session must have expired or been reset. //TODO: Do something useful with this info, log it, etc. //update the cookie with the new session start time cookies.Remove("SessionStarted"); SessionCookie.Value = DateTime.Now.ToString(); context.Response.Cookies.Add(SessionCookie); //Redirect to the whatever page you want to handle this situation. //An error page, login page, etc. context.Response.Redirect("~/Login.aspx", true); } }
Remember Me
a@href@title, i, strike, u
Copyright © 2003-2008 Falafel Software Inc.
Subscribe to Falafel Blogs
The opinions expressed herein are Falafel's employees own personal opinions and do not represent Falafel Software's view in any way in case they go bananas!