天天看点

*.ashx文件

.ashx 文件用于写web handler的。其实就是带HTML和C#的混合文件。当然你完全可以用.aspx 的文件后缀。使用.ashx 可以让你专注于编程而不用管相关的WEB技术。.ashx必须包含IsReusable. 如下例所示

<% @ 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");

}

}

.ashx比.aspx的好处在与不用多一个html   

*ashx文件

using System.Web

*ashx文件

public sealed class TextBuilder : IHttpHandler

*ashx文件
*ashx文件
*ashx文件

{

*ashx文件

    public void ProcessRequest(HttpContext context)

*ashx文件
*ashx文件
*ashx文件
*ashx文件

        context.Response.ClearContent();

*ashx文件

        context.Response.ContentType = "text/plain";

*ashx文件

        context.Response.Write("Hello World");

*ashx文件

        context.Response.End();

*ashx文件

    }

*ashx文件
*ashx文件

    public bool IsReusable

*ashx文件
*ashx文件
*ashx文件
*ashx文件
*ashx文件

        get 

*ashx文件

{ return true; }

*ashx文件
*ashx文件
*ashx文件
*ashx文件

<%

*ashx文件

@ WebHandler language="C#" Class="MyNamespace.TextBuilder" codebehind="TextBuilder.ashx.cs" %>