You can have a look at the bundle transforms. It is not a complex process and does not require disabling browser cache for the whole application. The downside is that it doesn´t gives you too much control over the response, although it gives you the option to disable the browser caching.
Please note that with this approach you can only set cache-control as no-cache
and you cannot set it as no-store
. So I am not sure if your client would accept that! (If this doesn´t help, it might be worth keeping an eye on new features for bundle transforms, as they plan to give more control over the cache headers as per this SO response)
If you think this will be enough, then start by creating a new transform DisableCacheOverHttpsTransform
that implements IBundleTransform
. The transform will check if the current request is over a secure connection and in that case it will disable browser caching for the bundle:
public class DisableCacheOverHttpsTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
if (context.HttpContext.Request.IsSecureConnection)
{
//disable cache on https
response.Cacheability = HttpCacheability.NoCache;
}
}
}
Now all you need to do is make sure your script and css bundles use this transform. You can use this code to add this transform to all bundles (this should be at the end of your RegisterBundles(BundleCollection bundles)
method):
public static void RegisterBundles(BundleCollection bundles)
{
...
//Discomment to try bundling in debug
//BundleTable.EnableOptimizations = true;
var transform = new DisableCacheOverHttpsTransform();
foreach (var bundle in bundles)
{
bundle.Transforms.Add(transform);
}
}
With these changes, when your application is running over https, the responses for your script and css bundles will include the headers Cache-Control:no-cache
and Pragma:no-cache
.
Hope it helps!