Skip to content

Instantly share code, notes, and snippets.

@DDzia
Created January 29, 2019 22:12
Show Gist options
  • Save DDzia/9fe540ac39b7d5e67db946310a810ce9 to your computer and use it in GitHub Desktop.
Save DDzia/9fe540ac39b7d5e67db946310a810ce9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace WebApplication5
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public override void Init()
{
EndRequest += (sender, args) =>
{
var res = HttpContext.Current.Response;
// enable cache-control injection if caching strategy has not been setted manually
if (!res.Headers.AllKeys.Any(x => x.Equals("Cache-Control", StringComparison.InvariantCultureIgnoreCase)))
{
res.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
Debug.WriteLine("The Cache-Control was been added.");
}
Debug.WriteLine("The Cache-Control header is exists.");
};
base.Init();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment