Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

 

 

How to update an image in an Asp.Net website when the Browser Cache is turned on.

If I display a picture on a web page and change it with the upload, then the new picture is not displayed because the browser has cached the previous picture in the cache.

Can I update the browser cache?

 

Image output

<img src="@Html.Raw(ViewData["Profil_Image"] />

 

 

Solution:

In asp mvc core, the image address is extended with a query parameter and a current time

Example:

<img src="@Html.Raw(ViewData["Profil_Image"] + "?" + DateTime.Now.Ticks)" />

 

In the website

<img src="/User_Files/User_Images/400/User_Image_1.jpg?636582684020015936" >

 

 

 

Asp View, Asp Razor MVC Core

@{

    ViewData["Title"] = "📝 User Profil Image" ;

    ViewData.AddActivePage(ManageNavPages.UserImage);

}

 

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Upload_Image</title>

</head>

<body>

    <span style="margin-top:10px;"> Profil Image:</span>

    <br />

    <form asp-controller="Manage" asp-action="User_Profil_Image_Upload" method="post"

          enctype="multipart/form-data">

 

        <input type="file" name="uploaded_File" />

        <button type="submit" style="">Upload</button>

    </form>

 

    <br />

    @if (ViewData["Profil_Image"] !="")

    {

    <img src="@Html.Raw(ViewData["Profil_Image"] + "?" + DateTime.Now.Ticks)" alt="Uploaded Image" />

    <br />

    }

 

 

    @if (ViewData["Error"] != null)

    {

    <label>Error= @ViewData["Error"]</label>

    }

 

    <br />

</body>

</html>

 

 

Mobile
»
HTML: Move the position of an element only up to a certain position
»
Javascript: attach event to all children
»
Asp: Display image refreshed despite browser cache
»
Show Emoticons as Black and White Graphics
»
jQuery Example: Convert text to number, swap image
»
How can I copy something to the clipboard with a button from a web page?
»
Javascript: how to get the URL of the current website
»
Javascript: Query dialog OK Cancel
»
Bilder automatisch in der Größe anpassen mit CSS
»
Javascript: change style in javascript

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de