1、一个简单的ashx
public class ClientData : BasePage, IHttpHandler { protected HttpContext context; //方法中用到 public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //结果按原样输出文本 this.context = context; var action = context.Request["action"]; //接收ajax的url地址参数 eg:url: "Handle/ProviderHandle.ashx?action=GetAirLines", switch (action) { case "queryInvoiceOrders": queryInvoiceOrders(); break; case "updateInvoiceOrders": updateInvoiceOrders(); break; } } }
2、接收数据
//可以获取任何方式 string value = context.Request.Params["User"]; //可以获取任何方式 string value = context.Request["key"] //POST方式传参,直接根据表单控件的name属性访问Request.Form string user = context.Request.Form["User"]; //GET方式传参 string user = context.Request.QueryString["User"];