Display Image using ashx Handler

前端 未结 3 566
[愿得一人]
[愿得一人] 2020-12-02 00:33

I have the following image in my aspx page


 \" 




        
相关标签:
3条回答
  • 2020-12-02 00:56

    The ImageUrl only replaces the tilde (~) in the control markup.

    Try this instead:

    string imageUrl = "~/AvatarImageFetch.ashx?memberid=" + memberid.ToString();
    LargeImage.ImageUrl = Page.ResolveUrl(imageUrl);
    
    0 讨论(0)
  • 2020-12-02 01:10

    Try the following in your ProcessRequest method:

    context.Response.ContentType = "image";
    
    using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
    {
           str.Write(objData.ToArray(), 0, objData.ToArray().Length);
           Byte[] bytes = str.ToArray();
           context.Response.BinaryWrite(bytes);
    }
    

    where objData is the value you are reading from the database

    0 讨论(0)
  • 2020-12-02 01:11

    Try setting the ContentType:

    context.Response.ContentType = "image/png";
    

    http://www.dotnetperls.com/ashx

    0 讨论(0)
提交回复
热议问题