抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

ashx 文件接收请求

比如新建一个 CustomerHandler.ashx 文件,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 文件中发送请求

1
2
3
4
MyProject.CustomAshx customer = new MyProject.CustomAshx();
//添加参数
HttpContext.Current.Items.Add("CustomerId", "123");
customer.ProcessRequest(HttpContext);

评论