如何为单个图像(单个页面)禁用缓存?

时间:2012-04-09 07:24:05

标签: c# asp.net

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;
        ...
}

1 个答案:

答案 0 :(得分:3)

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

<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";