Skip to content

Commit 44d9408

Browse files
committed
Ignore cookies if it's been more than 100 minutes #105
1 parent 9ec3a73 commit 44d9408

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Griddly.Mvc/GriddlyContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ public class GriddlyFilterCookieData
2929
{
3030
public Dictionary<string, string[]> Values { get; set; }
3131
public SortField[] SortFields { get; set; }
32+
public DateTime? CreatedUtc { get; set; }
3233
}
3334
}

Griddly.Mvc/GriddlyCookieFilterValueProvider.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,16 @@ public override IValueProvider GetValueProvider(ControllerContext controllerCont
6666
{
6767
var data = JsonConvert.DeserializeObject<GriddlyFilterCookieData>(cookie.Value);
6868

69-
context.CookieData = data;
70-
context.IsDefaultSkipped = true;
71-
72-
return new GriddlyCookieFilterValueProvider(context);
69+
// chrome/ff don't delete session cookies if they're set to "continue where you left off"
70+
// https://stackoverflow.com/questions/10617954/chrome-doesnt-delete-session-cookies
71+
// only use a cookie if it's new within 100 minutes
72+
if (data.CreatedUtc != null && (DateTime.UtcNow - data.CreatedUtc.Value).TotalMilliseconds < 100)
73+
{
74+
context.CookieData = data;
75+
context.IsDefaultSkipped = true;
76+
77+
return new GriddlyCookieFilterValueProvider(context);
78+
}
7379
}
7480
catch
7581
{

Griddly.Mvc/GriddlyParameterAttribute.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public override void OnActionExecuted(ActionExecutedContext filterContext)
8787

8888
GriddlyFilterCookieData data = new GriddlyFilterCookieData()
8989
{
90-
Values = new Dictionary<string, string[]>()
90+
Values = new Dictionary<string, string[]>(),
91+
CreatedUtc = DateTime.UtcNow
9192
};
9293

9394
if (context.SortFields?.Length > 0)

0 commit comments

Comments
 (0)