Triyng来检索和显示图像从数据库... 我已在其中我有此一个HttpHandler:显示图像(来自数据库)基于雇员的图像控制的图像控制
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
Dim employeeId As Integer
If (Not (context.Request.QueryString("employeeId")) Is Nothing) Then
employeeId = Convert.ToInt32(context.Request.QueryString("employeeId"))
Else
Throw New ArgumentException("No parameter specified")
End If
Dim imageData() As Byte = {}
' get the image data from the database using the employeeId Querystring
context.Response.ContentType = "image/jpeg"
' You can retrieve this also from the database
context.Response.BinaryWrite(imageData)
End Sub
Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
bind()
GridView1.Visible = "True"
ProcessRequest(Context)
End Sub
错误:The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
我哪里错了?我需要做什么改变?
这是窗体上的图像控制:
<asp:Image ID="Image1" runat="server" imageUrl="HttpHandler.ashx?employeeId=5"/>
@Stefano阿尔铁:
这是Employee.aspx
Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
bind()
GridView1.Visible = "True"
Image1.ImageUrl = "~/HttpHandler.ashx?EmployeeID='" & EmailIDTextBox.Text & "'"
End Sub
,这是上HttpHandler.ashx
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
Dim employeeId As Integer
If (Not (context.Request.QueryString("employeeId")) Is Nothing) Then
employeeId = Convert.ToInt32(context.Request.QueryString("employeeId"))
Else
Throw New ArgumentException("No parameter specified")
End If
Dim imageData() As Byte = {}
' get the image data from the database using the employeeId Querystring
context.Response.ContentType = "image/jpeg"
' You can retrieve this also from the database
context.Response.BinaryWrite(imageData)
End Sub
你知道哪里有异常被抛出行? – 2013-03-04 09:42:03
当我打电话ProcessRequest(即,当它应该去httphandler(.ashx页面)) – adityawho 2013-03-04 09:44:05
另外...我有点困惑...这是一个页面或HTTP处理程序?它不能都是..你必须在一个单独的ashx文件中实现http处理程序 – 2013-03-04 09:44:19