晚安-早-晚-等^_^
我在尝试在 asp:Image (使用 Web 表单)中显示图像时遇到问题,作为 byte[] 存储在数据库中 - 找到了很多相当明确的答案,如何做到这一点,所以现在我有一个处理程序:
public class ShowImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//creating object, working with db
var core = new CoreHolder();
var picture = core.PictureRepository.Read(Convert.ToInt32(context.Request.QueryString["id"]))
context.Response.Clear();
context.Response.ContentType = picture.PictureMimeType;
//trying to write byte[]
context.Response.BinaryWrite(picture.PictureData);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
...以及我的 .aspx 页面中的此类字符串:
<asp:Image ID="Image1" runat="server" ImageUrl="~/ShowImageHandler.ashx?id=<%#:Item.ID %>" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/ShowImageHandler.ashx?id=1>" />
问题是:好的,程序输入带有 id 的 ProcessRequest,如果是第二个 asp-image 字符串,它会找到带有数据的图片,但即使在尝试 BinaryWrite 之前,我也可以看到,context.Response 中有异常。输出流:长度,位置 - System.NotSupportedExeption,读/写超时 - System.InvalidOperationExeption。如果是第一个字符串(它在 ListView ItemTemplate 中使用),OutputStream 问题仍然存在+所有试图从查询字符串中获取 id 的压力。
请帮忙)