2

On my site there is a page where a user can see a list of all the payments they need to make, select a file, and make that payment. The problem I am having is if the user makes a payment on a file and then types in the URL of the payment grid page a cached page appears still showing the file that has already been paid, allowing the user to submit a second payment. What I would like to do is always go through the controller so if the user types in this URL they would re-generate the model and this file would no longer appear. Is there a way to turn of caching for a certain page? Any ideas on how to work around this?

1 Answer 1

2

You could create a custom action filter to set proper response headers in order to instruct the browser not to cache the results of the page:

public class DisableCacheAttribute : ActionFilterAttribute { public override void OnResultExecuting(ResultExecutingContext filterContext) { var cache = filterContext.HttpContext.Response.Cache; cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetNoStore(); cache.SetExpires(DateTime.UtcNow.AddDays(-1)); cache.SetValidUntilExpires(false); cache.SetCacheability(HttpCacheability.NoCache); } } 

and then decorate the controller action with this attribute:

[DisableCache] public ActionResult PerformPayment() { ... } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.