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); + } + } +}