Hi jewel!
You’re running into a browser caching issue
. When you upload a new image with the same file name and path, the browser still shows the old image because it’s loading it from its cache. That’s why you only see the new image after restarting your PC (which clears the cache).
#Here is how to fix!:
- Add a query string to your image URL in your
.cshtml
file.
This makes the browser think it’s a new image every time the query string changes, so it will always fetch the latest version from the server.
##For example, change this:
<img src="~/Contain/websiteimage/WebsiteAllimge/@(shift.Path)" alt="Image Not Set">
#To this:
<img src="~/Contain/websiteimage/WebsiteAllimge/@(shift.Path)?v=@(shift.LastUpdated.Ticks)" alt="Image Not Set">
- Here,
shift.LastUpdated
should be a property in your model that you update every time the image changes (for example, set it toDateTime.Now
when you upload a new image).
#If you don’t have a LastUpdated
property, you can use a random number or the current time, like this:
<img src="~/Contain/websiteimage/WebsiteAllimge/@(shift.Path)?v=@(DateTime.Now.Ticks)" alt="Image Not Set">
- The browser sees the URL as different each time (because of the
?v=...
part), so it fetches the new image from the server instead of using the cached one.
Hope this helps!