I have created my custom authentication. Now I want to disable cache of broswer on log off button click. How should I do that? What should I include in log off action?
I'm following: http://www.bradygaster.com/custom-authentication-with-mvc-3.0
You can point cache dir to null using startup arguments for chrome. This will disable any caching.
You can use the OutputCacheAttribute to control server and/or browser caching for specific actions or all actions in a controller.
If you want to disable caching of all files in a folder and its subfolders you can add a Web. config in the root folder you want to disable browser caching for. Say you wanted to disable browser caching for the files in the folder js/nocache and all subfolders, then you would place the Web. config here: js/nocache/Web.
In ASP.NET MVC, there is an OutputCache filter attribute that you can apply and this is the same concept as output caching in web forms. The output cache enables you to cache the content returned by a controller action. Output caching basically allows you to store the output of a particular controller in the memory.
Is your concern the browser back button after logging off?
If yes, then you should not disable the cache on log off. You should disable it on all pages that you don't want to be cached which in your case would be all authentciated pages.
This could be done by writing a custom action filter:
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var response = filterContext.HttpContext.Response;
response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
response.Cache.SetValidUntilExpires(false);
response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Cache.SetNoStore();
}
}
and then decorating your actions with it:
[Authorize]
[NoCache]
public ActionResult Foo()
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With