替换文件夹中同名图像

发布于 2024-07-19 02:01:01 字数 464 浏览 5 评论 0原文

A.) 当我使用代码删除 Pics 文件夹中的 Image123.jpg 时,我上传另一个图像并将该图像重命名为 Image123.jpg 并将其放入 Pics 文件夹中,由于某种原因,新图像得到了显示但它使用我删除的图像的尺寸。 使用此处的中继器来显示图像.................

B.) 当我将 Image99.jpg 复制并粘贴到我的图片文件夹中时所有准备好的内容都包含 Image99.jpg 那么当然它会更改原始图像。 因此,出于某种原因,它必须被缓存,因为当我运行我的页面时,它仍然显示第一个图像。 在这里使用普通的图像控件......

为什么它会执行AB...... ..我该如何解决这个问题...问题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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眼睛不忧郁 2024-07-26 02:01:01

浏览器会缓存图像,因此如果您替换图像,则必须更改请求图像的 url 才能查看新图像。

您可以通过以下方式执行此操作:

  1. 更改图像本身的名称。

  2. 将查询字符串添加到您更改的 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:

  1. Changing the name of the image itself.

  2. 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.

私藏温柔 2024-07-26 02:01:01

如果确实是缓存问题,您可以执行以下操作。

以编程方式:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

以声明方式:

<%@ OutputCache Location="None" VaryByParam="None" %>

通过缓存网页,您可以避免在后续请求中重新创建信息,因此请记住,这可能会对页面加载时间产生不利影响,因为缓存将被禁用。

If it is indeed a caching issue you could do the following.

Programmatically:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Declaratively:

<%@ OutputCache Location="None" VaryByParam="None" %>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文