如何以编程方式删除的OutputCache的ASCX?
-
20-09-2019 - |
题
我有一个page1.aspx这个:
<%@ Register src="uc1.ascx" tagname="UcHead" tagprefix="uc1" %>
和uc1.ascx使用OutputCache
:
<%@ OutputCache Duration="18000" VaryByParam="*" %>
我怎样才能在另一个page2.aspx点击一个按钮删除OutputCache
为uc1.ascx或Page1.aspx的?
当所述的OutputCache处于page1.aspx这个,我可以使用以下代码来除去的OutputCache:
string url = "/page1.aspx";
HttpResponse.RemoveOutputCacheItem(url);
但当的OutputCache处于uc1.ascx它不起作用。
解决方案
确定尝试此
在用户控件看跌期权的页面加载:
HttpRuntime.Cache.Insert("myCacheKey", DateTime.Now);
BasePartialCachingControl pcc = Parent as BasePartialCachingControl;
pcc.Dependency = new CacheDependency(null, new string[]{"myCacheKey"});
更改关键看你希望它是你控制什么的。
然后在要清除缓存投放事件的代码:
Cache.Insert("myCacheKey", DateTime.Now);
我看到在 http://dotnetslackers.com/ASP_NET/re-63091_ASP_NET_clear_user_control_output_cache.aspx此溶液
我测试,它似乎工作,虽然我必须刷新页面再次后,我把这种喜欢看到更新后的控制内容。
不隶属于 StackOverflow