1

I have a HTTP Handler which does not fire. i just noticed that adding a break to my code.

The strange thing is the page where the handler is called and the HTTPhandler have the same namespaces ... I really don't understand why ....

Did anyone face that lately ? thanks in advance

EDIT:

My ImageHandler.ashx.cs:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Actilog.Parametre.Famille
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ImageHandler : IHttpHandler
    {

        string strcon = ConfigurationManager.AppSettings["DB_CRACQConnectionString"].ToString();
        public void ProcessRequest(HttpContext context)
        {
            string imageid = context.Request.QueryString["ImID"];
            SqlConnection connection = new SqlConnection(strcon);
            connection.Open();
            SqlCommand command = new SqlCommand("select Image from Table_test where ImageID=" + imageid, connection);
            SqlDataReader dr = command.ExecuteReader();
            dr.Read();
            context.Response.BinaryWrite((Byte[])dr[0]);
            connection.Close();
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

the page where i call it:

<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="False" 
    CssClass="Gridview" HeaderStyle-BackColor="#7779AF" 
    HeaderStyle-ForeColor="white">
    <Columns>
        <asp:BoundField DataField="ImageName" HeaderText="Image Name" />
        <asp:TemplateField HeaderText="Image">
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" Height="150px" 
                    ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID") %>' Width="150px" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

my Web.config part:

<httpHandlers>
  <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
  <remove verb="*" path="*.asmx" />
  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      validate="false" />
  <!-- *******  Register the RadUploadProgressHandler for IIS prior to v.7  ****** -->
  <add path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler"
      verb="*" validate="false" />
</httpHandlers>
5
  • How are you calling the handler from page?
    – Ramesh
    Mar 13, 2012 at 14:52
  • Try adding more context to the question, post the code, web.config section, etc. As it stands is impossible to answer.
    – Icarus
    Mar 13, 2012 at 14:53
  • please show some source and the config...
    – Yahia
    Mar 13, 2012 at 14:53
  • i added my web.config as well
    – user1173169
    Mar 13, 2012 at 15:00
  • I don't see the handler registered in your web.config
    – Ramesh
    Mar 13, 2012 at 15:04

1 Answer 1

0

In your web.config you should add:

<httpHandlers>
    ...
    <add path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
      verb="*" validate="false" />
    ...
</httpHandlers>

To allow Asp.Net to manage every requests containig "ImageHandler.ashx" with the correct IHttpHandler class. And remember to add:

<system.webServer>
    <handlers>
    ...
    <add name="ImageHandler" path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
          verb="*" validate="false" />
    ...
    </handlers>
</system.webServer>

In your production environment (if your using IIS7+).

3
  • Have you tried to place a breakpoint in the ProcessRequest of the handler? The first step is to understand if the handler fires or not.
    – tanathos
    Mar 13, 2012 at 15:16
  • 1
    Yes i tried, visual studio does not stop... so the handler is not firing
    – user1173169
    Mar 13, 2012 at 15:18
  • 2
    And have you tried to check if the url inside the image is correct? What happens if you paste this url directly to the browser?
    – tanathos
    Mar 13, 2012 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.