Server.Transfer to an HttpHandler

好久不见. 提交于 2019-12-22 05:17:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!