问题
I have an IHttpHandler with the following ProcessRequest method:
public void ProcessRequest(HttpContext context) {
int id = Convert.ToInt32(context.Request.QueryString["id"] + 151);
var xml = XDocument.Parse("<xml><cartid>" + id + "</cartid></xml>");
context.Response.Write(xml);
}
Which I'm trying to use from an aspx page as follows:
protected void Page_Load(object sender, EventArgs e) {
order o = new order();
Server.Transfer(o, false);
}
I get an HttpException: Error executing child request for handler 'PostTest.order'.
If I instead try doing the transfer like:
Server.Transfer("~/order.ashx?id=65", false)
I get an HttpException: Error executing child request for /order.ashx.
Am I doing this wrong or is there another way to accomplish what I want?
回答1:
Just pass the context:
var handler = new order();
handler.ProcessRequest(Context);
Response.End();
来源:https://stackoverflow.com/questions/6865025/server-transfer-to-an-httphandler