Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I already have stored image into database using below code
HTML
user.UserImage = new Byte[image1.ContentLength];
                   image1.InputStream.Read(user.UserImage, 0, image1.ContentLength);


Now I want to Store this into session and Retrieve on Dashboard Page.

But image is not showing. pls help.

What I have tried:

In Controller:
HTML
string imageDataURL = string.Format("data:image/png;base64,{0}", dataitem.UserImage);
               Session["UserImage"] =  imageDataURL;

In View:

HTML
var img =  (Session["UserImage"]);
                                  
  string imageSrc = string.Format("data:image/gif;base64,{0}", img);
  <img src="@imageSrc" width = "60" height = "60" class="img-profile rounded-circle"/>
Posted
Updated 29-Jun-20 6:49am

1 solution

The data you store in the Session already has the data:image/gif prefix, however you add it again in your view, so just miss that step out

@{
    var img = (Session["UserImage"]);
}
<img src="@img" width="60" height="60" class="img-profile rounded-circle" />


Also you don't seem to be converting the byte array to base64, if dataitem.UserImage is a byte array then use

string imageDataURL = string.Format("data:image/png;base64,{0}", System.Convert.ToBase64String(dataitem.UserImage));
 
Share this answer
 
Comments
[no name] 29-Jun-20 13:05pm    
Thanks a lot F-ES Sitecore

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900