We have an old ASP.NET application. We have an image element on one of the pages. For the security purpose we would like to stream the image instead of a direct reference. However, after the data link is generated from the stream, it appears to be permanent. Even after the application is closed, the data link is still alive.
Is there a way to make this link invalid when out of session, to somehow invalidate it, by maybe emptying a stream?
Please let me know
Thank you in advance
MemoryStream ms = new MemoryStream();
string physicalPath = "some path of an image";
using (FileStream fs = new FileStream(physicalPath, FileMode.Open, FileAccess.Read))
{
fs.CopyTo(ms);
}
img.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray(), 0, ms.ToArray().Length);
2
Answers
Found a solution
Changes the above code to
Where the code for the MyImage.aspx is
You may consider placing a javascript code that change the element "src" attribute when the session is expired.