Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Handler.ashx not being called (VB.NET)

Posted on 2013-06-14
20
Medium Priority
?
758 Views
Last Modified: 2013-06-23
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.ProcessRequest
            'context.Response.ContentType = "text/plain";
            'context.Response.Write("Hello World");
            Me.SetLog()
            ds = New DataSet

            Try
                context.Response.AddHeader("Cache-Control", "private,must-revalidate,post-check=1,pre-check=2,no-cache")
                context.Response.ContentType = "image/jpeg"
                Dim img() As Byte

                If ((Not (context.Request.QueryString("PID")) Is Nothing) _
                            AndAlso (context.Request.QueryString("PID").ToString <> "")) Then
                    Dim pid As Integer = CInt(context.Request.QueryString("PID"))
                    img = _pers.GetSignature(pid)

                    If img.Length <> 0 Then
                        context.Response.BinaryWrite(img)
                    End If

                    'If (Not (ds) Is Nothing) Then
                    '    If (ds.Tables("Signature").Rows(0)("Signature") IsNot System.DBNull.Value) Then
                    '        img = DirectCast(ds.Tables("Signature").Rows(0)("Signature"), Byte())
                    '        context.Response.BinaryWrite(img)
                    '    End If
                    'End If
                End If

            Catch ex As Exception
                log.Error("Missing QueryString: " & ex.Message)
            End Try
        End Sub
0
Comment
Question by:foxbari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 2
20 Comments
 
LVL 21

Expert Comment

by:66866
ID: 39253280
Assuming your VB.Net and C# code does the same thing, did you try putting a break point and debug?
0
 

Author Comment

by:foxbari
ID: 39253298
Yes. It won't even debug. The page is rendered immediately.
This is VS 2010 if that makes a difference.
Thanks for your response.
0
 
LVL 21

Expert Comment

by:66866
ID: 39253452
Dumb question- did you compile your code?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:foxbari
ID: 39253460
Yes. Explicitly.
Build Succesdful each time.
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39253781
Can you test with a trace?, visit your GridView and then press Ctrl + F5
0
 

Author Comment

by:foxbari
ID: 39253903
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?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39254111
If you visit explicitly the handler?
0
 

Author Comment

by:foxbari
ID: 39254126
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
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39254189
the URL of the image could be something like this: htpp://www.yourdomain.com/yourhandler.ashx?PID=4
0
 

Author Comment

by:foxbari
ID: 39254414
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>
                                        &nbsp;<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?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39254468
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?
0
 

Author Comment

by:foxbari
ID: 39257132
The Webhandler directive doesn't have a trace attribute.
0
 

Author Comment

by:foxbari
ID: 39257134
When I call the handler directly from the browser, I just get a blank page.
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39257153
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
0
 

Author Comment

by:foxbari
ID: 39257227
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.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                  </listeners>
            </trace>
      </system.diagnostics>

They don't do a damn thing.
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39257333
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>

Open in new window

0
 

Author Comment

by:foxbari
ID: 39257367
Interesting...

When I run the handler from the browser with this code including the BinaryWrite:

                Dim pid As Integer = CInt(context.Request.QueryString("PID"))
                context.Response.Write("Did I get here?" & " " & pid)
                ds = _pers.GetPersonnel(pid)

                If ((ds) IsNot System.DBNull.Value) Then
                    If (ds.Tables("Personnel").Rows(0)("Signature") IsNot System.DBNull.Value) Then
                        img = CType(ds.Tables("Personnel").Rows(0)("Signature"), Byte())
                        context.Response.Write(" How about here? Length = " & img.Length)
                        context.Response.BinaryWrite(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.
0
 

Accepted Solution

by:
foxbari earned 0 total points
ID: 39257426
I think I got it.

It's the way VB.NET handles System.DBNull vs Nothing vs C# null
VB.NET is for #$%^!

Thanks for your help. Much obliged!
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39257656
the interesting thing is that you say that the handler isn't called without that change in the code
0
 

Author Closing Comment

by:foxbari
ID: 39269100
Learned about web.config <handler> and <Listener>
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question