我有一个page1.aspx这个:
I have a page1.aspx:
<%@ Register src="uc1.ascx" tagname="UcHead" tagprefix="uc1" %>和uc1.ascx使用的OutputCache :
and uc1.ascx using the OutputCache:
<%@ OutputCache Duration="18000" VaryByParam="*" %>我怎么可以在另一个page2.aspx点击一个按钮来删除的OutputCache 为uc1.ascx或page1.aspx这个?
How can I click a button in another page2.aspx to remove OutputCache for uc1.ascx or page1.aspx?
当的OutputCache在page1.aspx这个,我可以使用下面的code去除的OutputCache:
When the OutputCache is in page1.aspx, I can use the following code to remove the OutputCache:
string url = "/page1.aspx"; HttpResponse.RemoveOutputCacheItem(url);但是,当的OutputCache是uc1.ascx这是行不通的。
But it does not work when the OutputCache is in uc1.ascx.
推荐答案好吧试试这个
在用户控件放的页面加载速度:
In the page load of your user control put:
HttpRuntime.Cache.Insert("myCacheKey", DateTime.Now); BasePartialCachingControl pcc = Parent as BasePartialCachingControl; pcc.Dependency = new CacheDependency(null, new string[]{"myCacheKey"});更改关键看你希望它是你控制什么的。
Change the key to whatever you want it to be for your control.
然后在事件code要清除高速缓存的说:
Then in the code of the event that you want to clear the cache put:
Cache.Insert("myCacheKey", DateTime.Now);我看到在dotnetslackers/ASP_NET/re-63091_ASP_NET_clear_user_control_output_cache.aspx
我测试,它似乎工作,虽然我必须刷新页面再次后,我把这种喜欢看到更新的控制内容。
I tested it and it seems to work, although I do have to refresh the page once again after I call this like to see the updated control content.
更多推荐
如何以编程方式删除的OutputCache为ASCX?
发布评论