首页 > 解决方案 > Missing Loading Image From Database Use Handler.ashx

问题描述

I use the Handler.ashx to get and display images from database. But they didn't all display, only 100% after request few times. I don't know how to solve.

Handler.ashx code:

public void ProcessRequest(HttpContext context)
{
    if (context.Request.QueryString["ImageID"] != null)
    {
        Byte[] bytes;
        string _strModelCode = context.Request.QueryString["ImageID"];
        try
        {
            bytes = ModelBLL.GetImage(_strModelCode);
        }
        catch
        {
            bytes = null;
        }
        context.Response.ContentType = "Image/jpg";
        if (bytes != null)
        {
            try
            {
                context.Response.BinaryWrite(bytes);
            }
            catch { }
        }
        context.Response.End();
        return;
    }
}

Image Loading Code:

foreach (GridViewRow _row in gridDispaly.Rows)
        {
            Image img = (Image)_row.FindControl("imgModel");
            img.ImageUrl = "../Handler.ashx?ImageID=" + _row.Cells[0].Text;
        } 

Thank you!

Error Loading Image From Database

标签: asp.netdatabaseimage

解决方案


推荐阅读