HTTP 处理程序问题
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
方法声明
应该是
The method declaration
should be
你的方法声明是错误的。
这应该可以做到:
MSDN 链接:
http://msdn.microsoft.com/de-de /library/system.web.ihttphandler.isreusable.aspx
干杯:)
your method declaration is wrong.
This should do it:
MSDN link:
http://msdn.microsoft.com/de-de/library/system.web.ihttphandler.isreusable.aspx
Cheers :)
尝试:
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.