Hoang Tran
Hoang Tran

Reputation: 956

How to modify Cache-Control setting in HttpResponse

My ASPNET Zero alway reload all css and js files instead of using cache. That is the reason it was too slow. So how can I change this setting value?

enter image description here

Upvotes: 0

Views: 325

Answers (2)

Hoang Tran
Hoang Tran

Reputation: 956

I have found the reason, the ASPNET Zero disable Client cache by default. My solution is just commented a line of code as below

protected override void Application_BeginRequest(object sender, EventArgs e)
{
    base.Application_BeginRequest(sender, e);
    //DisableClientCache();
}

private void DisableClientCache()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(CacheExpireDate);
    Response.Cache.SetNoStore();
}

Upvotes: 1

ryan.c
ryan.c

Reputation: 264

You can add asp-append-version="true" to the script or link tags in the razor pages where your css/js files are included.

Abp does provide dynamic scripts which are created at runtime creation. As such, there are limitations to what you can cache as discussed at https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3673

Upvotes: 1

Related Questions