1

我是 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

有没有人有任何想法?

提前致谢

4

3 回答 3

3

方法声明

Public Sub ProcessRequest(ByVal context As HttpContext)

应该

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
于 2011-07-27T12:18:24.217 回答
0

你的方法声明是错误的。这应该这样做:

Public Sub ProcessRequest(context As HttpContext) 

MSDN 链接:http: //msdn.microsoft.com/de-de/library/system.web.ihttphandler.isreusable.aspx

干杯:)

于 2011-07-27T11:53:54.890 回答
0

尝试:

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

您还需要 IsReusable 属性的实现。

于 2011-07-27T12:13:10.417 回答