替换文件夹中同名图像
A.) 当我使用代码删除 Pics 文件夹中的 Image123.jpg 时,我上传另一个图像并将该图像重命名为 Image123.jpg 并将其放入 Pics 文件夹中,由于某种原因,新图像得到了显示但它使用我删除的图像的尺寸。 使用此处的中继器来显示图像.................
B.) 当我将 Image99.jpg 复制并粘贴到我的图片文件夹中时所有准备好的内容都包含 Image99.jpg 那么当然它会更改原始图像。 因此,出于某种原因,它必须被缓存,因为当我运行我的页面时,它仍然显示第一个图像。 在这里使用普通的图像控件......
为什么它会执行A和B...... ..我该如何解决这个问题...问题A对我来说更重要,因为当用户单击“更改徽标”按钮时我需要更改图像名称。
A.) When i use code to delete lets say Image123.jpg in folder Pics and i upload another image and rename that image also Image123.jpg and place it into folder Pics for some reason the new image get's displayed but its using the dimensions of the Image i delete. Using a Repeater over here to display the image.................
B.) When i just copy and past say Image99.jpg into my Pics folder that all ready contain a Image99.jpg then of course it changes the original one. So for some reason it must get cached because when i run my page it is still shows the first Image. Using a normal Image control over here................
Why is it doing A and B........and how can i go around this.....Problem A it more important to me because i need to change the Images names when the User clicks on "Change Logo" button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器会缓存图像,因此如果您替换图像,则必须更改请求图像的 url 才能查看新图像。
您可以通过以下方式执行此操作:
更改图像本身的名称。
将查询字符串添加到您更改的 URL。
如果在url中添加版本号,例如
images/Image123.jpg?version=42
,并且在替换图片时增加版本号,浏览器会向服务器请求新图片作为浏览器根据完整的 url 而不仅仅是文件名来缓存文件。The browser caches the images, so if you replace an image you have to change the url that requests the image to see the new image.
You can do this either by:
Changing the name of the image itself.
Add a querystring to the url, which you change.
If you add a version number to the url, e.g.
images/Image123.jpg?version=42
and increase the version number when you replace the image, the browser will request the new image from the server as the browser caches the files based on the complete url, not just the file name.如果确实是缓存问题,您可以执行以下操作。
以编程方式:
以声明方式:
通过缓存网页,您可以避免在后续请求中重新创建信息,因此请记住,这可能会对页面加载时间产生不利影响,因为缓存将被禁用。
If it is indeed a caching issue you could do the following.
Programmatically:
Declaratively:
By caching Web pages, you avoid re-creating information on subsequent requests so keep in mind that this may adversely affect page load times as caching will be disabled.