避免图像缓存 [英] Avoiding Image Caching

查看:87
本文介绍了避免图像缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找到一种方法来防止我网站上的图片被缓存在用户的计算机上。我想避免这种情况,因为在Image控件中使用的图像经常会改变,但名称相同。当它们被缓存时,将显示缓存的图像,这不是我想要的。我以为

使用

Response.Cache.SetCacheability(HttpCacheability.No Cache)


会实现这一点,但它似乎只能阻止缓存的.aspx文件来自

。有没有办法阻止图像被缓存?

-

Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/

I have been trying to find a way to prevent the images on my site from being
cached on the user''s machine. I want to avoid this because the images used
in an Image control often change, yet have the same name. When they are
cached, the cached image is displayed which is not what I want. I thought
that using
Response.Cache.SetCacheability(HttpCacheability.No Cache)

would have achieved this, but it seems to only prevent the .aspx file from
being cached. Is there any way to prevent images from being cached as well?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

推荐答案

Nathan,


我不确定这是否会这样做(我没试过)。在这个示例中,我在程序中制作了

图像,但是你当然可以使用读取来实现。

现在你可以通过它的页面获取图像url


\\\

Private Sub Page_Load(ByVal sender As System.Object,_

ByVal e As System.EventArgs )处理MyBase.Load

Response.Cache.SetExpires(DateTime.Now.AddTicks(50 0))

Dim myForeBrush As Brush = Brushes.Black

Dim myFont As New Font(Times New Roman,8,FontStyle.Regular)

Dim textHeight As Single

Dim bm As New Bitmap(120, 20)

Dim g As Graphics = Graphics.FromImage(bm)

g.Clear(Color.White)

Dim textSize As SizeF = g.MeasureString(now.tostring,myFont)

g.DrawString(Now.ToString,myFont,myForeBrush,_

新RectangleF(0,0,120,20) )

Dim ms As New IO.MemoryStream

Dim arrImage()As Byte

bm.Save(ms,Imaging.ImageFormat.Bmp)

arrImage = ms.GetBuffer

Response.BinaryWrite(arrImage)

g.dispose

End Sub

// /


我希望这会有所帮助,


Cor
Nathan,

I am not sure if this will do it (I did not try it). In this sample I make
the image in the procedure, however you can do it of course using a read.
Now you can get the image by its page url

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Cache.SetExpires(DateTime.Now.AddTicks(50 0))
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
Dim textHeight As Single
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g.MeasureString(now.tostring, myFont)
g.DrawString(Now.ToString, myFont, myForeBrush, _
New RectangleF(0, 0, 120, 20))
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
bm.Save(ms, Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
g.dispose
End Sub
///

I hope this helps,

Cor


我不喜欢我认为这是缓存。检查服务器上的新图像是否比旧版本具有后期创建日期,如果不是旧版本将显示。

通过拥有2张图像来测试,aaa。 jpg,在服务器上放置一个带有较旧创建的日期

日期并浏览到它,现在将较新的一个放在服务器上,

浏览到它和第二个将显示,一切正常。

现在将它们重命名为bbb.jpg,首先将具有较新创建日期的那个

放在服务器上,浏览,现在是较旧的创建日期,浏览,第1张图片

仍显示。


" Nathan Sokalski" < NJ ******** @ hotmail.com>在消息中写道

新闻:#Q ************** @ TK2MSFTNGP15.phx.gbl ...
I don''t think it is caching. Check that the new image on the server has a
later create date than the older, if not the older will be shown.
Test this by having 2 images, aaa.jpg, put the one with the older creation
date on the server and browse to it, now put the newer one on the server,
browse to it and the 2nd one will show, all OK.
Now rename them to bbb.jpg, first put the one with the newer creation date
on the server, browse, now the older creation date, browse, the 1st image
still shows up.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:#Q**************@TK2MSFTNGP15.phx.gbl...
我一直在尝试找到一种方法来防止我的网站上的图像被
缓存在用户的机器上。我想避免这种情况,因为在Image控件中使用的图像经常会改变,但名称相同。当它们被缓存时,会显示缓存的图像,这不是我想要的。我认为使用
Response.Cache.SetCacheability(HttpCacheability.No Cache)

会实现这一点,但它似乎只能阻止.aspx文件从
被缓存。有没有办法阻止图像被缓存为
? -
Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/
I have been trying to find a way to prevent the images on my site from being cached on the user''s machine. I want to avoid this because the images used
in an Image control often change, yet have the same name. When they are
cached, the cached image is displayed which is not what I want. I thought
that using
Response.Cache.SetCacheability(HttpCacheability.No Cache)

would have achieved this, but it seems to only prevent the .aspx file from
being cached. Is there any way to prevent images from being cached as well? --
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



我同意Chris的意见 - 但是如果你想确保这不会发生,请使用

HTTPHandler来绘制自己的图像 - 然后他们就不能窃取你的带宽

;-) http://www.uberasp.net/GetArticle.aspx?id=13

" Cor Ligthert [MVP]" <无************ @ planet.nl>在消息中写道

新闻:eE ************** @ TK2MSFTNGP14.phx.gbl ...
I agree with Chris - but if you want to make sure this doesn''t happen, use a
HTTPHandler to draw your own images - then they can''t steal your bandwidth
either ;-) http://www.uberasp.net/GetArticle.aspx?id=13
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eE**************@TK2MSFTNGP14.phx.gbl...
Nathan,
我不确定这是否会这样做(我没试过)。在这个示例中,我在程序中制作了图像,但是你当然可以通过阅读来实现。
现在你可以通过它的页面获取图像了。

\私有Sub Page_Load(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理MyBase.Load
Response.Cache.SetExpires(DateTime.Now.AddTicks (50 0))
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font(Times New Roman,8,FontStyle.Regular)
Dim textHeight As Single
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g。 MeasureString(now.tostring,myFont)
g.DrawString(Now.ToString,myFont,myForeBrush,_
New RectangleF(0,0,120,20))
Dim ms As New IO .MemoryStream
Dim arrImage()As Byte
bm.Save(ms,Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
g.dispose
End Sub
///

我希望这有帮助,

Cor
Nathan,

I am not sure if this will do it (I did not try it). In this sample I make
the image in the procedure, however you can do it of course using a read.
Now you can get the image by its page url

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Cache.SetExpires(DateTime.Now.AddTicks(50 0))
Dim myForeBrush As Brush = Brushes.Black
Dim myFont As New Font("Times New Roman", 8, FontStyle.Regular)
Dim textHeight As Single
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim textSize As SizeF = g.MeasureString(now.tostring, myFont)
g.DrawString(Now.ToString, myFont, myForeBrush, _
New RectangleF(0, 0, 120, 20))
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
bm.Save(ms, Imaging.ImageFormat.Bmp)
arrImage = ms.GetBuffer
Response.BinaryWrite(arrImage)
g.dispose
End Sub
///

I hope this helps,

Cor



这篇关于避免图像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆