Generic handler not returning response on hosted environment

543 views Asked by At

Generic Handler doesn't return response on hosted environment

I'm trying to host my application which is built using ASP.NET. It has a simple html file calling javascript where I have an ajax call requesting response from a Generic handler(.ashx). The application runs fine on my local but it doesn't work on hosted environment.

When I debug the javascript on hosted site, the response it is returning is

"<%@ WebHandler Language=\'C#\' CodeBehind=\"GetInfo.ashx.cs" Class=\"MyProject.GetInfo\" %> \r\n" in the success data element on ajax.

I'm new to this hosting and I'm not sure If my ajax request is wrong or If I'm publishing it wrong. I just used simple publish option on visual studio and posted all the files to hosting environment.

Here is my ajax request:

            $.ajax({
                type: "GET",
                url: "/Handlers/GetInfo.ashx",
                contentType: "application/json; character=utf-8",
                success: function (data) {
                    if (data.status == "OK") {
                     //some code here

                    }
                }
            });

Here is my handler:

GetInfo.ashx.cs

public class GetInfo: IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
       context.Response.Write(JsonConvert.SerializeObject (new { status = "OK" }));   

    }

}
1

There are 1 answers

4
Ricardo Peres On

Make sure you have this in your web.config file (locally it should be in global web.config):

<system.web>
  <httpHandlers>
    <add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory, System.Web" validate="True"/>
  </httpHandlers>
</system.web>