Friday, January 15, 2010

ashx

Just discover what is ashx in asp.net, it is nothing but the httphandler that we used in MOSS.

Creating a new ashx, is actually creating a class that inherit from IHttpHandler. Instead of loading xml from page load event in typical asp.net web form, ashx could be the best option for you to do the same tasks.

Example,


public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;

string sXml = BuildXMLString(); //not showing this function,
//but it creates the XML string

context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Write( sXml );
}

No comments:

Post a Comment