Last active
September 28, 2020 08:28
-
-
Save lkaczanowski/4058253 to your computer and use it in GitHub Desktop.
Session Expire Filter Attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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