我有个页面A显示用户的照片, 照片的名字就是用户id.jpg
然后在另一个页面B里用户可以上传新照片,然后会替代原来的照片,还叫id.jpg
在B修改完照片后会跳转回A,
现在的问题是, 跳转回A后显示出来的照片还是旧照片,必须手动刷新页面后才变成新照片我觉得可能是因为浏览器缓存保存了旧的照片, 因为与新照片同名,
所以页面Load的时候,照片没下完时就直接从缓存里面读了旧的照片,不知道想法对不对?
而且这个怎么解决啊,不能总让用户手动刷新啊? 大家给点思路

解决方案 »

  1.   

    想法是对的。
    加在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()
      

  2.   


    底下那个加参数的方法我已经试过了,在chrome里面解决了问题,但是IE里面无效。
    这段代码在IE里面也没有效果...
      

  3.   

    那加上上面清除的代码。然后在读取下新的相片呢?
    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里面
      

  4.   


    事实上chrome也不好用, 我发现每次第一次修改就肯定无效。
    从第二次开始就变正常了... 很奇怪 这到底是为什么呢?
      

  5.   

    清除所有缓存
        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();
        } 
      

  6.   

    可以在A页面加一个linkbutton
    如<asp:linkbutton id="linkBtnPostBack" runat="server">然后写一个脚本
    脚本里面会去点击这个linkbutton从B页面过去的时候调用这个脚本,页面应该就刷新了。
      

  7.   

    如果简单地“解决”,你可以在新的页面B与原来的页面B的url上做出区别。例如csdn这样就是随机产生不一样的编码。你的新的页面的url完全可以用一个随机产生“?rnd=adkfqie3rqwiwe”做参数,这样就能让浏览器不去使用缓存。
      

  8.   


    我页面跳转回原来页用的是如下代码Response.Redirect("~/requirement.aspx?");我觉得这样不应该有错吧
      

  9.   

    我在跳转回的url里面加了个# 貌似图片还是第一次读取旧的 f5才变成新的