Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Asp: Display image refreshed despite browser cache

02.04.2018 (👁4479)

 

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>