如何以编程方式删除的OutputCache为ASCX? [英] how to remove OutputCache programmatically for ascx?

查看:117
本文介绍了如何以编程方式删除的OutputCache为ASCX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);

我看到在<一本解决方案href=\"http://dotnetslackers.com/ASP%5FNET/re-63091%5FASP%5FNET%5Fclear%5Fuser%5Fcontrol%5Foutput%5Fcache.aspx\" rel=\"nofollow\">http://dotnetslackers.com/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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆