Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response cache does not work for the view that contain form element #3064

Closed
TanvirArjel opened this issue Apr 17, 2018 · 3 comments
Closed

Comments

@TanvirArjel
Copy link
Contributor

Response cache does not work on the following method which returns view containing a form element.If the form element is removed from the view then response cache works. why it is happening?

 [Route("Contact")]
 [ResponseCache(Duration = 3600)] //Does not working for this method
 public IActionResult Contact()
 {
     return View();
 }

 [HttpPost]
 [Route("Contact")]
 public IActionResult Contact(ContactViewModel contactViewModel, IFormFile attachment)
 {
     //Necessary opertaion goes here
     return
     View(contactViewModel);
 }

@Tratcher
Copy link
Member

Look at the response headers. Is this happening because the form has anti-forgery enabled which always sets no-cache headers?

@TanvirArjel
Copy link
Contributor Author

TanvirArjel commented Apr 20, 2018

@Tratcher Yes! anti-forgery was enabled and that's why response cache was not working..My question is why response cache does not work when anti-forgery in enabled?

@Tratcher
Copy link
Member

The anti-forgery token in the form is attached to a cookie and neither should be cached or else they could get out of sync.

@Eilon Eilon closed this as completed Jul 13, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants