public class AverageHandler : IHttpHandler
{
public bool IsReusable
{ get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write("hello");
}
}
.ashx比.aspx的好处在与不用多一个html
-----------------------------------------------------------------------------
大概去年九月的时候,做一个功能就是生成图片,当然有很多方法,生成图片放在服务器的某个目录下面,隔一段时间就删除,图还得自己画,嫌麻烦,结果找着这样一段代码,今天看到使用.ashx文件处理IHttpHandler实现发送文本及二进制数据的方法。突然发现这种用法讨论的很好,也许是没怎么详细介绍它的官方中文文档吧,并且推荐另外一种方法代替。
// ----------------------------------------
// Pick your favorite image format
// ------------------------------
byte[] byteArr = (byte[]) oChartSpace.GetPicture ("png", 500, 500);
// ----------------------------------------
// Store the chart image in Session to be picked up by an HttpHandler later
// ---------------------------------------
HttpContext ctx = HttpContext.Current;
string chartID = Guid.NewGuid ().ToString ();
<!--Since we are grabbing all requests after this, make sure Error.aspx does not rely on .Text -->
<add verb="*" path="Error.aspx" type="System.Web.UI.PageHandlerFactory" />