If you develop with ASP.NET, you probably spend most of your time creating .aspx files with .cs files as code behind (or perhaps you use .ascx files for your controls -- and .asmx files for web services). But have you created a .ashx file (web handler). A web handler file works just like an aspx file except you are one step back away from the messy browser level where HTML and C# mix. One reason you would write an .ashx file instead of an .aspx file is that your output is not going to a browser but to an xml-consuming client of some kind. Working with .ashx keeps you away from all the browser technology you don't need in this case. Notice that you have to include the IsReusable property.
<% @ webhandler language="C#" class="AverageHandler" %>
using System;
using System.Web;
public class AverageHandler : IHttpHandler
{
public bool IsReusable
{ get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write("hello");
}
}
Comments