0

I have an MVC4 app with asp.net with jquery the project load all pages at firs time then update contents via ajax.

After log off of the app, all pages remain on cache. It cause that in the next login, new data are mixed with old data or some data are repeated.

How can I do to delete all cache at log off?

1 Answer 1

1

I am assuming the the browser is the one caching the page. If this is the case, you can't simply remove the cache from the browser when they log off.

Instead, you will need to tell the browser to not cache any of the pages.

You can do this with a simple action filter and override the OnResultExecuting method

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
        filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        base.OnResultExecuting(filterContext);
    }
Sign up to request clarification or add additional context in comments.

6 Comments

THis method are located in account controller ?
amazing, tks for your help.
Just a final question, It prevents to cache or delete actual cache ? (the browsers cache)
It won't add it to its cache.
Also, you might want to add: filterContext.HttpContext.Response.Cache.SetNoStore(); This will make sure that not even proxy servers keep a copy.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.