foxbari
asked on
Handler.ashx not being called (VB.NET)
I'm having a problem in asp.NET VB.NET. I have an image displayed from a db in a bound gridview.
My process doesn't call handler.ashx?PID-(PID) in my VB.nET version of this app but it works in my C# version.
I don't get it.
Thanks
Code:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessReques t
'context.Response.ContentT ype = "text/plain";
'context.Response.Write("H ello World");
Me.SetLog()
ds = New DataSet
Try
context.Response.AddHeader ("Cache-Co ntrol", "private,must-revalidate,p ost-check= 1,pre-chec k=2,no-cac he")
context.Response.ContentTy pe = "image/jpeg"
Dim img() As Byte
If ((Not (context.Request.QueryStri ng("PID")) Is Nothing) _
AndAlso (context.Request.QueryStri ng("PID"). ToString <> "")) Then
Dim pid As Integer = CInt(context.Request.Query String("PI D"))
img = _pers.GetSignature(pid)
If img.Length <> 0 Then
context.Response.BinaryWri te(img)
End If
'If (Not (ds) Is Nothing) Then
' If (ds.Tables("Signature").Ro ws(0)("Sig nature") IsNot System.DBNull.Value) Then
' img = DirectCast(ds.Tables("Sign ature").Ro ws(0)("Sig nature"), Byte())
' context.Response.BinaryWri te(img)
' End If
'End If
End If
Catch ex As Exception
log.Error("Missing QueryString: " & ex.Message)
End Try
End Sub
My process doesn't call handler.ashx?PID-(PID) in my VB.nET version of this app but it works in my C# version.
I don't get it.
Thanks
Code:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessReques
'context.Response.ContentT
'context.Response.Write("H
Me.SetLog()
ds = New DataSet
Try
context.Response.AddHeader
context.Response.ContentTy
Dim img() As Byte
If ((Not (context.Request.QueryStri
AndAlso (context.Request.QueryStri
Dim pid As Integer = CInt(context.Request.Query
img = _pers.GetSignature(pid)
If img.Length <> 0 Then
context.Response.BinaryWri
End If
'If (Not (ds) Is Nothing) Then
' If (ds.Tables("Signature").Ro
' img = DirectCast(ds.Tables("Sign
' context.Response.BinaryWri
' End If
'End If
End If
Catch ex As Exception
log.Error("Missing QueryString: " & ex.Message)
End Try
End Sub
Assuming your VB.Net and C# code does the same thing, did you try putting a break point and debug?
ASKER
Yes. It won't even debug. The page is rendered immediately.
This is VS 2010 if that makes a difference.
Thanks for your response.
This is VS 2010 if that makes a difference.
Thanks for your response.
Dumb question- did you compile your code?
ASKER
Yes. Explicitly.
Build Succesdful each time.
Build Succesdful each time.
Can you test with a trace?, visit your GridView and then press Ctrl + F5
ASKER
Nope. Handler.ashx isn't even called. I've even tried RowDataBound but the image needs to have a container and that didn't work either.
Is there a vs property I need to set?
Is there a vs property I need to set?
If you visit explicitly the handler?
ASKER
I tried that, too! It won't stop in the handler. I'm setting the ImageUrl in the Gridview Template field. What is the proper format string for the ImageURL?
Could that be the problem?
I don't receive any errors except if I misform the Image tag the in markup.
Thanks
Could that be the problem?
I don't receive any errors except if I misform the Image tag the in markup.
Thanks
the URL of the image could be something like this: htpp://www.yourdomain.com/yourhandler.ashx?PID=4
ASKER
Ok. Here's my markup:
<asp:TemplateField HeaderText="Signature">
<HeaderStyle Font-Bold="True" CssClass="header" Wrap="False" />
<ItemTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# "Handler2.ashx?PID=" & Eval("PersonnelID") %>' Height="30px"
Width="187px" />
</ItemTemplate>
<ItemStyle BorderWidth="6px" />
<FooterTemplate>
<asp:HyperLink ID="lbSignature" runat="server" Font-Names="Arial" Font-Size="10pt"
NavigateUrl='<%# "Signature.aspx?PID=" & Eval("PersonnelID") %>' Text="Add Signature"></asp:HyperLink >
</FooterTemplate>
</asp:TemplateField>
I'm all out of options.
What am I missing?
<asp:TemplateField HeaderText="Signature">
<HeaderStyle Font-Bold="True" CssClass="header" Wrap="False" />
<ItemTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# "Handler2.ashx?PID=" & Eval("PersonnelID") %>' Height="30px"
Width="187px" />
</ItemTemplate>
<ItemStyle BorderWidth="6px" />
<FooterTemplate>
<asp:HyperLink ID="lbSignature" runat="server" Font-Names="Arial" Font-Size="10pt"
NavigateUrl='<%# "Signature.aspx?PID=" & Eval("PersonnelID") %>' Text="Add Signature"></asp:HyperLink
</FooterTemplate>
</asp:TemplateField>
I'm all out of options.
What am I missing?
I would start to know why the handler.ashx isn't been called, put a trace and call the handler directly from the browser:
Verify if there is a GET registered in the trace.axd
Right click on the result and view the source, what does it show?
ASKER
The Webhandler directive doesn't have a trace attribute.
ASKER
When I call the handler directly from the browser, I just get a blank page.
My friend, setup the trace in the web.config, is obvious that the handler doesn't have a trace directive.
In the blank page, right click and choose the option "View source", let me know what does it show
In the blank page, right click and choose the option "View source", let me know what does it show
ASKER
View Source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></ HEAD>
<BODY></BODY></HTML>
web.config settings:
<httpHandlers>
<add verb="*" path="Handler.ashx" type="ARAdmin.Handler" />
</httpHandlers>
<trace enabled="true" requestLimit="40" localOnly="false" pageOutput="true"/>
</system.web>
<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener "
type="System.Web.WebPageTr aceListene r, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</listeners>
</trace>
</system.diagnostics>
They don't do a damn thing.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></
<BODY></BODY></HTML>
web.config settings:
<httpHandlers>
<add verb="*" path="Handler.ashx" type="ARAdmin.Handler" />
</httpHandlers>
<trace enabled="true" requestLimit="40" localOnly="false" pageOutput="true"/>
</system.web>
<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener
type="System.Web.WebPageTr
</listeners>
</trace>
</system.diagnostics>
They don't do a damn thing.
Can you try with this web.config content?
<system.web>
<httpHandlers>
<add path="Handler.ashx" type="ARAdmin.Handler" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="MyHandler" path="Handler.ashx" type="ARAdmin.Handler" verb="*"/>
</handlers>
</system.webServer>
ASKER
Interesting...
When I run the handler from the browser with this code including the BinaryWrite:
Dim pid As Integer = CInt(context.Request.Query String("PI D"))
context.Response.Write("Di d I get here?" & " " & pid)
ds = _pers.GetPersonnel(pid)
If ((ds) IsNot System.DBNull.Value) Then
If (ds.Tables("Personnel").Ro ws(0)("Sig nature") IsNot System.DBNull.Value) Then
img = CType(ds.Tables("Personnel ").Rows(0) ("Signatur e"), Byte())
context.Response.Write(" How about here? Length = " & img.Length)
context.Response.BinaryWri te(img)
Else
context.Response.Write(" Didn't make it ")
End If
End If
...all I get is just a blank image with a 'x'
BUT when I run this code without the BinaryWrite.
I get the output text in the Response.Write statements.
When I run the handler from the browser with this code including the BinaryWrite:
Dim pid As Integer = CInt(context.Request.Query
context.Response.Write("Di
ds = _pers.GetPersonnel(pid)
If ((ds) IsNot System.DBNull.Value) Then
If (ds.Tables("Personnel").Ro
img = CType(ds.Tables("Personnel
context.Response.Write(" How about here? Length = " & img.Length)
context.Response.BinaryWri
Else
context.Response.Write(" Didn't make it ")
End If
End If
...all I get is just a blank image with a 'x'
BUT when I run this code without the BinaryWrite.
I get the output text in the Response.Write statements.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the interesting thing is that you say that the handler isn't called without that change in the code
ASKER
Learned about web.config <handler> and <Listener>
Thanks
Thanks