[英]How can I remove a browser's cache server-side, using ASP.NET?
如何使用 ASP.NET (C#) 删除浏览器的缓存服务器端?
优惠券自行显示(我相信它来自缓存,因为我也浏览了其他服装网站)。 它破坏了我的 JavaScript 以及我的服务器端代码,因为我将 UpdatePanel 用于 Ajax,并且它复制了 UpdatePanel 的 ID。 我已经重命名了 UpdatePanel 的 ID,但它没有区别。 它会生成“无效的视图状态”异常。 优惠券名称为“FastSave”
我尝试过的:
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
你可以像这样停止缓存:
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
}
以下是我在 ASP.NET MVC 2 应用程序中设置客户端浏览器缓存的方法:
public class CacheFilterAttribute : ActionFilterAttribute {
/// <summary>
/// Gets or sets the cache duration in seconds. The default is 10 seconds.
/// </summary>
/// <value>The cache duration in seconds.</value>
public int Duration { get; set; }
public CacheFilterAttribute() { Duration = 10; }
public override void OnActionExecuted(ActionExecutedContext filterContext) {
if (Duration <= 0) return;
var cache = filterContext.HttpContext.Response.Cache;
var cacheDuration = TimeSpan.FromSeconds(Duration);
cache.SetCacheability(HttpCacheability.Public);
cache.SetExpires(DateTime.Now.Add(cacheDuration));
cache.SetMaxAge(cacheDuration);
cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
}
}
你不能。
您可以告诉客户端不要缓存某些内容,但是一旦缓存,服务器端就没有清除缓存的机制。 您必须等待缓存过期或用户清除缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.