Search code examples
c#asp.net.nethttphandler

Ashx handler's processrequest function is not called


I am writing a handler to process a resource and I am facing an issue, when the implemented IHttpHandler Class is written under a namespace.

Please find the code

Not working scenario

Web.config:

<add name="ResourceHandler" type="PublicSite.Classes.Handlers.ResourceEndpoint, PublicSite" path="Resource.ashx" verb="*" />

Property: PublicSite.Classes.Handlers.ResourceEndpoint.IsReusable=False

Issue: Constructor is hit and the ProcessRequest is not invoked. Constructs the object of the class, ie., Constructor is hit , however fails by 404 before the processrequest is invoked.

Working Scenario

Web.config:

<add name="ResourceHandler" type="ResourceEndpoint,PublicSite" path="Resource.ashx" verb="*" />

Class: PublicSite.Classes.Handlers.ResourceEndpoint.IsReusable=True

Constructor is hit and fails by 404 before the processrequest is invoked.

Second time when we request for the handler, it straight away uses the constructed object so construcotr is not invoked and the ProcessRequest is invoked directly. By the way in the second call the handler is working.

I dont require the reusable property. Can some one help me to find the issue. Thanks.


Solution

  • Can you confirm to me that your web.config and handler itself looks like the following ? (This is from a project hosted under IIS 7.5)

    web.config: -

      <system.webServer>
        <handlers>
          <add name="customerHandler" 
               preCondition="integratedMode" 
               verb="*" 
               path="customerHandler.ashx"
               type="GlassCMS.HttpHandlers.CustomerHandler, GlassCMS"/>
    .
    .
    .
        </handlers>
      </system.webServer>
    

    HttpHandler: -

        [WebService(Namespace = "http://{redacted.com}/json-http-handlers/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class CustomerHandler : IHttpHandler
        {
            public bool IsReusable
            {
                get { return false; }
            }
    
            public void ProcessRequest(HttpContext context)
            {
                string json = string.Empty;
    
                // code to do whatever here...
    
                context.Response.Write(json);
            }
    

    I can include the JavaScript as well if you want (or you can post yours here). This example above is from working code.