我正在开发一个简单的图像标记和搜索应用程序。我已经将我的图像上传到数据库,应用了标签,但是当我将它们拉回来时失败了 - 图像没有呈现。
我在 SO 上找到了这个,但我无法让它工作。
我想我可能误解了处理程序。
简而言之,在后面的代码中,我创建了一个 ASP:Image,将其 imageurl 设置为带有照片 ID 的处理程序,然后将该控件添加到 ASP:Placeholder。
当页面呈现时,在 IE 中,我得到那个小红色 x 没有图像的东西,而在 FF 中,什么也没有。
让我觉得我错过了什么的一件事是我的处理程序代码中的断点永远不会被命中。所以它甚至被执行。对?
有人知道我在这里做错了什么吗?谢谢。
这是我的处理程序
Imports aapeClsLib
Imports System.Web
Imports System.Web.Services
Public Class photos
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim img As Byte() = getImage(context.Request.QueryString("ID"))
context.Response.Clear()
context.Response.ContentType = "image/jpeg"
context.Response.BinaryWrite(img)
context.Response.End()
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Private Function getImage(ByVal id As String) As Byte()
Dim img As Byte()
Dim strSql As String = "select ph_photo from photos where ph_id = " & id
Dim dt As DataTable = sqLiteData.getDataTable(strSql)
img = CType(dt.Rows(0)(0), Byte())
Return img
End Function
End Class
以及我将其粘贴在占位符中的位置
Private Sub insertPhotos(ByVal dt As DataTable)
For Each row As DataRow In dt.Rows
Dim img As New Image
img.ImageUrl = "photos.ashx?ID=" & row(0)
PlaceHolder1.Controls.Add(img)
Next
End Sub