0

ASP.NET 图像缓存问题(如何禁用它?) .IE 浏览器从目录 C:\Documents and Settings...\Local Settings\Temporary Internet Files 加载旧图像

   protected void Page_Load(object sender, EventArgs e)
    {
        MembershipUser user = Membership.GetUser();
      imCropped.ImageUrl = (File.Exists(Server.MapPath("..") + @"\Users\" + user.ProviderUserKey.ToString() + @"\" + user.ProviderUserKey.ToString() + ".gif"))? "~/Users/" + user.ProviderUserKey.ToString() + "/" + user.ProviderUserKey.ToString() + ".gif" : "~/Images/thumb.gif";
}

protected void ButtonJcrop_Click(object sender, EventArgs e)
    {

       ...

        String mapPath = @"\Users\" + user.ProviderUserKey.ToString() + @"\" + user.ProviderUserKey.ToString() + ".gif";
        bmpCropped.Save(Server.MapPath("..") + mapPath);
        imCropped.ImageUrl = Request.ApplicationPath + mapPath;
        ...
}
4

1 回答 1

4

您可以使用随机数添加到 img url aquery 字符串参数:

<img src="http://www.walaa.co.il/t.jpg?c=2342342"/>

它可以像Datetime.Ticks或其他东西。

ImageUrl = (File.Exists(string.Format("{0}\\Users\\{1}\\{1}.gif?c={2}", Server.MapPath(".."), user.ProviderUserKey.ToString(), DateTime.Now.Ticks))) ? string.Format("~/Users/{0}/{0}.gif?c={1}" , user.ProviderUserKey.ToString(), DateTime.Now.Ticks) : "~/Images/thumb.gif";
于 2012-04-09T07:26:37.037 回答