我有个页面A显示用户的照片, 照片的名字就是用户id.jpg
然后在另一个页面B里用户可以上传新照片,然后会替代原来的照片,还叫id.jpg
在B修改完照片后会跳转回A,
现在的问题是, 跳转回A后显示出来的照片还是旧照片,必须手动刷新页面后才变成新照片我觉得可能是因为浏览器缓存保存了旧的照片, 因为与新照片同名,
所以页面Load的时候,照片没下完时就直接从缓存里面读了旧的照片,不知道想法对不对?
而且这个怎么解决啊,不能总让用户手动刷新啊? 大家给点思路
然后在另一个页面B里用户可以上传新照片,然后会替代原来的照片,还叫id.jpg
在B修改完照片后会跳转回A,
现在的问题是, 跳转回A后显示出来的照片还是旧照片,必须手动刷新页面后才变成新照片我觉得可能是因为浏览器缓存保存了旧的照片, 因为与新照片同名,
所以页面Load的时候,照片没下完时就直接从缓存里面读了旧的照片,不知道想法对不对?
而且这个怎么解决啊,不能总让用户手动刷新啊? 大家给点思路
加在pageload里面
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("cache-control", "private");
HttpContext.Current.Response.CacheControl = "no-cache";
或者在返回A页面地址加个随机数。a.jpg?rand="+Math.random()
底下那个加参数的方法我已经试过了,在chrome里面解决了问题,但是IE里面无效。
这段代码在IE里面也没有效果...
Page_Load 事件中
Page.Response.Buffer = false;
Page.Response.Cache.SetNoStore();
返回的链接加上Response.Redirect(url.asp?'+Math.random());
不行的话在用下面这个函数。
/// <summary>
/// 清除IE缓存
/// </summary>
private void ClearIECache()
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + "del /f /s /q \"%userprofile%\\Local Settings\\Temporary Internet Files\\*.*\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
string result = process.StandardOutput.ReadToEnd();
}
//
pageload里面
事实上chrome也不好用, 我发现每次第一次修改就肯定无效。
从第二次开始就变正常了... 很奇怪 这到底是为什么呢?
protected void RemoveAllCache()
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
ArrayList
al = new ArrayList();
while (CacheEnum.MoveNext())
{ al.Add(CacheEnum.Key);
}
foreach (string key
in al)
{
_cache.Remove(key);
}
show();
}
如<asp:linkbutton id="linkBtnPostBack" runat="server">然后写一个脚本
脚本里面会去点击这个linkbutton从B页面过去的时候调用这个脚本,页面应该就刷新了。
我页面跳转回原来页用的是如下代码Response.Redirect("~/requirement.aspx?");我觉得这样不应该有错吧