Imports System
Imports System.Web
Imports System.Data.SqlClient
Public Class HTTPHandler : Implements IHttpHandler
Private _start As String = ConfigurationManager.AppSettings("Shoppingcart").ToString()
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim imageid As String = context.Request.QueryString("ImID")
Dim connection As New SqlConnection(_start)
connection.Open()
Dim command As New SqlCommand("select PhotoURl from Products where ProductID=" & imageid, connection)
Dim dr As SqlDataReader = command.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(DirectCast(dr(0), [Byte]()))
connection.Close()
context.Response.[End]()
End Sub
can u check that code please as nothing happening,i'm trying to display an image by using the query string parameter
Jdaniel13
Member
20 Points
176 Posts
handle.ashx and query string
Oct 29, 2012 03:58 PM|LINK
Imports System Imports System.Web Imports System.Data.SqlClient Public Class HTTPHandler : Implements IHttpHandler Private _start As String = ConfigurationManager.AppSettings("Shoppingcart").ToString() Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim imageid As String = context.Request.QueryString("ImID") Dim connection As New SqlConnection(_start) connection.Open() Dim command As New SqlCommand("select PhotoURl from Products where ProductID=" & imageid, connection) Dim dr As SqlDataReader = command.ExecuteReader() dr.Read() context.Response.BinaryWrite(DirectCast(dr(0), [Byte]())) connection.Close() context.Response.[End]() End Subcan u check that code please as nothing happening,i'm trying to display an image by using the query string parameter
<asp:Image id="Image1" runat="server" ImageUrl='<%# string.Format("HTTPHandler.ashx?ImID={0}", Eval("ProductID")) %>' Height="150px" Width="150px"/>
here is the code for presentation layer
Neodynamic
Participant
1008 Points
289 Posts
Re: handle.ashx and query string
Oct 30, 2012 12:03 PM|LINK
if you hardcode the URL for displaying the image through the handler e.g.
<asp:Image id="Image1" runat="server" ImageUrl="~/HTTPHandler.ashx?ImID=12345" Height="150px" Width="150px"/>
where 12345 should be changed to some valid productid.
If you do that, do you get the image? If not, then the issue is with your http handler trying to get the image bytes from the db.
PS: DO NOT use straight SQL commands!!! in doing that you are exposing your code to security hacks. create a SP or use SqlParameter class.