在浏览器关闭中删除缓存项 [英] Removing Cache item on Browser Close
本文介绍了在浏览器关闭中删除缓存项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我目前有一些代码可以在用户登录应用程序时创建缓存项目。
我想知道如果用户在没有注销的情况下关闭浏览器,我将如何删除此缓存项?
Hi
I currently have some code which creates a cache item when a user signs into the application.
I would like to know how would i be able to remove this cached item if the user closes the browser without signing out?
推荐答案
你无法处理在许多浏览器中一致地关闭按钮事件。
因此,最好设置缓存数据的到期时间。
例如,当您登录时,您可以设置缓存过期到30.
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(30));
另一种方法可能是有一个注销按钮并添加以下代码 -
You cannot handle the close button event consistently across many browsers.
As a result, it may be best to set an expiry on cache data.
For e.g.when you logon, you could set the cache expire to 30.
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(30));
Another approach could be to have a logout button and add the following code -
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
这篇关于在浏览器关闭中删除缓存项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文