Mehdi
Mehdi

Reputation: 1126

ResponseCache always set Cache-Control to no-cache, no-store in ASP.net core

I want to cache the home page in the client browser

But after setting the ResponseCache attribute, the response header is set to Cache-Control: no-cache, no-store

After reading Response cache not working in asp.net core project and ResponseCache not working in net core 3.1 I can't fix this

[ResponseCache(Duration = 300)]
public class HomeModel : PageModel
{

    public const string PageName = "Home";

    public void OnGet()
    {
    }
}

CacheControl

Upvotes: 4

Views: 3095

Answers (2)

Mehdi
Mehdi

Reputation: 1126

Because I add a form in _layout.cshtml for search field an anti forgery token generated in it automatically!

ASP.net core set Cache-Control: no-cache, no-store for each page which contains an anti forgery field or has Authorize attribute!

By moving this form from the _layout.cshtml, problem resolved!

Upvotes: 9

Mehdi
Mehdi

Reputation: 1126

Because I add a form in _layout.cshtml for search field an anti forgery token generated in it automatically!

ASP.net core set Cache-Control: no-cache, no-store for each page which contains an anti forgery field!

By moving this form from the _layout.cshtml, problem resolved!

Upvotes: -1

Related Questions