Skip to content

Instantly share code, notes, and snippets.

@lkaczanowski
Last active September 28, 2020 08:28
Show Gist options
  • Save lkaczanowski/4058253 to your computer and use it in GitHub Desktop.
Save lkaczanowski/4058253 to your computer and use it in GitHub Desktop.
Session Expire Filter Attribute
namespace Granite.Web.Services
{
using System.Web;
using System.Web.Mvc;
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContextBase httpContext = filterContext.HttpContext;
if (httpContext.Session != null)
{
if (httpContext.Session.IsNewSession)
{
// jezeli zostala utworzona nowa sesja, ale istnieja stare ciasteczka to oznacza to, ze mamy timeout
string sessionCookie = httpContext.Request.Headers["Cookie"];
if ((sessionCookie != null) && (sessionCookie.IndexOf("ASP.NET_SessionId", System.StringComparison.Ordinal) >= 0))
{
filterContext.Result = new RedirectToRouteResult("Error", null);
}
}
}
base.OnActionExecuting(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment