Server.Transfer to HttpHandler

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); } 

What I'm trying to use on 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 a child request for the 'PostTest.order' handler.

If I try to transfer instead, for example:

 Server.Transfer("~/order.ashx?id=65", false) 

I get an HttpException: A child request failed for /order.ashx.

Am I doing it wrong or is there another way to accomplish what I want?

+6
source share
1 answer

Just pass the context:

 var handler = new order(); handler.ProcessRequest(Context); Response.End(); 
+12
source

All Articles