I'm a newbie when it comes to HTTP handlers and i'm struggling to work out what the problemis with my current code
I seem to be getting this error
Class 'Handler' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'System.Web.IHttpHandler'.
When using this code
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.Configuration
Imports System.Data.SqlClient
Public Class Handler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext)
Dim connStr As String = ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
Dim con As New SqlConnection(connStr)
' Create SQL Command
Dim cmd As New SqlCommand()
cmd.CommandText = "Select * from My_Images" +
" where id =@id"
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = con
Dim ImageID As New SqlParameter("@investor", System.Data.SqlDbType.Int)
ImageID.Value = context.Request.QueryString("id")
cmd.Parameters.Add(ImageID)
con.Open()
Dim dReader As SqlDataReader = cmd.ExecuteReader()
dReader.Read()
开发者_如何学运维 context.Response.BinaryWrite(DirectCast(dReader("Image"), Byte()))
dReader.Close()
con.Close()
End Sub
Public ReadOnly Property IsReusable As Boolean _
Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
Has anyone got any ideas?
Thanks in advance
The method declaration
Public Sub ProcessRequest(ByVal context As HttpContext)
should be
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
your method declaration is wrong. This should do it:
Public Sub ProcessRequest(context As HttpContext)
MSDN link: http://msdn.microsoft.com/de-de/library/system.web.ihttphandler.isreusable.aspx
Cheers :)
Try:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
You will also need implements on the IsReusable property.
精彩评论