HTTP 处理程序问题

发布于 2024-11-26 17:07:31 字数 1503 浏览 1 评论 0原文

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

有人有任何想法吗?

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹿港巷口少年归 2024-12-03 17:07:31

方法声明

Public Sub ProcessRequest(ByVal context As HttpContext)

应该是

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

The method declaration

Public Sub ProcessRequest(ByVal context As HttpContext)

should be

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
下雨或天晴 2024-12-03 17:07:31

你的方法声明是错误的。
这应该可以做到:

Public Sub ProcessRequest(context As HttpContext) 

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

干杯:)

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 :)

聽兲甴掵 2024-12-03 17:07:31

尝试:

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

您还需要实现 IsReusable 属性。

Try:

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

You will also need implements on the IsReusable property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文