2
Reply

I sometimes see ASP.NET apps that include ASHX files. What are ASHX files?

Amit Das

Amit Das

Jun 20, 2007
6.8k
0

    .ashx files are web-handler files in asp.net programming and define IHttpHandler interface. Whenever an .ashx file is requested, ProcessRequest() method is invoked automatically. ProcessRequest() is a method where we do make changes according to our requirement. Handlers are used in URL routing, Image handling, binary data handling etc. as it support backward compatibility.

    Anil Kumar
    November 23, 2012
    0

    ASHX files contain HTTP handlers-software modules that handle raw HTTP requests received by ASP.NET. The following code institutes a simple HTTP handler:

    <%@ WebHandler Language="C#" Class="Hello"%>

    using System.Web;

    public class Hello : IHttpHandler
    {
        public void ProcessRequest (HttpContext context)
        {
            string name = context.Request["Name"];
            context.Response.Write ("Hello, " name);
        }

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

    If this code is placed in an ASHX file named Hello.ashx and requested using the URL http://.../hello.ashx?Name=Jeff, it returns "Hello, Jeff" in the HTTP response. ASHX files provide developers with a convenient way to deploy HTTP handlers without customizing CONFIG files or modifying the IIS metabase.

    Amit Das
    June 20, 2007
    0