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?
Server. Transfer() should be used when: we want to transfer current page request to another . aspx page on the same server. we want to preserve server resources and avoid the unnecessary roundtrips to the server.
An ASP.NET HTTP handler is the process that runs in response to a request that is made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes . aspx files. When users request an . aspx file, the request is processed by the page handler.
Redirect method redirects a request to a new URL and specifies the new URL while the Server. Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.
Just pass the context:
var handler = new order();
handler.ProcessRequest(Context);
Response.End();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With