ashx 文件接收请求
比如新建一个 CustomerHandler.ashx 文件,
namespace MyProject.CustomAshx
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Customer : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
int customerId = 0;
//接收参数
if (HttpContext.Current.Items["CustomerId"] != null)
customerId = HttpContext.Current.Items["CustomerId"].ToString();
context.Response.ContentType = "text/plain";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(customerId);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
asp.net CodeBehind 发送请求
在 aspx.cs 文件中发送请求
MyProject.CustomAshx customer = new MyProject.CustomAshx();
//添加参数
HttpContext.Current.Items.Add("CustomerId", "123");
customer.ProcessRequest(HttpContext);