![](/img/trans.png)
[英]How to clear the cache of an asp.net application from another asp.net application on the same server?
[英]How can we clear the server side cache in a button click in an asp.net application?
我对此有一个典型的要求。
我有一个在asp.net 4.0中开发的Web应用程序。 在这个应用程序中,我想在其中一个Web表单中添加一个按钮,它将执行以下任务:
现在,我知道我们可以通过删除此处存在的文件手动实现它,
%systemroot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
%systemroot%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
我们需要在删除临时文件之前关闭IIS,然后再重新启动它。 为了避免对缓存文件的任何依赖。
但我想知道如何在Web表单的按钮单击事件中实现它。 请帮我解决这个问题。
我目前在我的应用程序中使用以下内容:
public static void ClearAspNetCache(HttpContext context) {
foreach (DictionaryEntry entry in context.Cache) {
context.Cache.Remove((string)entry.Key);
}
}
这是一个可能非常有用的源参考:
如果要从缓存中删除所有项目,请尝试使用此选项:
IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();
while (enumerator.MoveNext())
{
HttpContext.Current.Cache.Remove(enumerator.Key);
}
从HttpContext.Current.Cache中删除项目不会清除您的IIS缓存。 它是服务器端缓存(由ASP.NET运行时管理),而不是Web服务器缓存。
看看这个链接。 http://blogs.msdn.com/b/dougste/archive/2008/08/11/clearing-out-temporary-asp-net-files.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.