简体   繁体   English

限制缓存图片asp.net

[英]Restrict caching images asp.net

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <ContentTemplate >
        <asp:Image  runat="server" id="img" style="max-width:100%"></asp:Image>

I have this image in updatePanel control. 我在updatePanel控件中有此图像。 And i change it's source in the code behind like this 我在这样的背后代码中更改了它的源

img.ImageUrl = "~/BackFile.ashx?ID=";

and backfile.ashx code is something like this: 和backfile.ashx代码是这样的:

Image img = Image.FromFile(getsrc());
        MemoryStream memStream = new MemoryStream();
        img.Save(memStream,
          System.Drawing.Imaging.ImageFormat.Jpeg);

        context.Response.ContentType = "image/jpeg";
        memStream.WriteTo(context.Response.OutputStream);

On my computer and oogle chrome everything worked well But then i tested it from another laptop on ie and opera and pictures stopped changing their sources. 在我的计算机和oogle chrome上,一切正常,但是随后我在另一台笔记本电脑上对它进行了测试,例如歌剧和图片停止更改其来源。 I think it 's because caching .so how can Ш restrict it? 我认为这是因为缓存。那么如何限制它呢? I just need pictures to refresh=) 我只需要图片即可刷新=)

UPD: it seems not be working in ie and opera UPD:在ie和Opera中似乎不起作用

You must set the headers to set no-cache. 您必须设置标题以设置无缓存。

context.Response.AddHeader("Cache-Control", "no-cache");
context.Response.Expires = 0;
context.Response.Cache.SetNoStore();
context.Response.AddHeader("Pragma", "no-cache");

and you should use below to ignore cached data by browser: 并且您应该使用以下命令来忽略浏览器缓存的数据:

img.ImageUrl = string.Format("~/BackFile.ashx?ID={0}&R={1}", <your ID>, randomNumber);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM