缓存问题。缓存问题
当我更改Image控件的ImageUrl属性时,浏览器有时会使用缓存,因此不会显示新图像。
如何解决问题,以便在更改ImageUrl属性后显示新图像?
这是我的代码:
string url = some code;
imgAvatar.ImageUrl = url;
缓存问题。缓存问题
当我更改Image控件的ImageUrl属性时,浏览器有时会使用缓存,因此不会显示新图像。
如何解决问题,以便在更改ImageUrl属性后显示新图像?
这是我的代码:
string url = some code;
imgAvatar.ImageUrl = url;
您可以通过添加下列选项
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.Buffer = true;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-store");
Response.Expires = -1441;
的另一种方式,以避免个别部件的缓存关掉网页缓存的东西乔尔在早期的StackOverflow播客讨论:上附加一个唯一的标识符作为HTTP参数要避免缓存的组件的url的结尾。然后在需要确保用户获得新版本时更新该标识符。
因此,如果您的网址是“http://www.mysite.com/images/myimage.png”,那么您可以使用“http://www.mysite.com/images/myimage.png?v=20110819a “
注意:通常这个技巧更适用于Javascript和/或CSS,而不是图像。
这工作得很好,而且很容易实现 – 2012-03-22 22:59:46