From 50acc1b136e9ad66f40c640d9c13d0404d14e5b9 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Tue, 7 Feb 2017 17:25:07 +0000 Subject: [PATCH] Added Cache Attribute to stop IE caching data. --- .../Helpers/CacheControlAttribute.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Helpers/CacheControlAttribute.cs diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Helpers/CacheControlAttribute.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Helpers/CacheControlAttribute.cs new file mode 100644 index 0000000..8e468e3 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Helpers/CacheControlAttribute.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http.Filters; + +namespace WindowsDataCenter.Helpers +{ + public class CacheControlAttribute : System.Web.Http.Filters.ActionFilterAttribute + { + public int MaxAge { get; set; } + + public CacheControlAttribute() + { + MaxAge = 3600; + } + + public override void OnActionExecuted(HttpActionExecutedContext context) + { + if (context.Response != null) + context.Response.Headers.CacheControl = new CacheControlHeaderValue() + { + Public = true, + MaxAge = TimeSpan.FromSeconds(MaxAge) + }; + + base.OnActionExecuted(context); + } + } +}