对于HTTP处理程序我是新手,我正在努力解决当前代码的问题
我似乎得到了这个错误
类'Handler'必须为接口'System.Web.IHttpHandler'实现'Sub ProcessRequest(context As HttpContext)'。
使用此代码时
<%@ 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
有没有人有任何想法?
提前致谢
答案 0 :(得分:2)
方法声明Public Sub ProcessRequest(ByVal context As HttpContext)
应为Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
答案 1 :(得分:0)
你的方法声明是错误的。 这应该这样做:
Public Sub ProcessRequest(context As HttpContext)
MSDN链接: http://msdn.microsoft.com/de-de/library/system.web.ihttphandler.isreusable.aspx
干杯:)
答案 2 :(得分:0)
尝试:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
您还需要IsReusable属性上的工具。