3
votes

I have code that returns an http response, but it also includes the content of the page. How can I create a response from scratch so it won't include anything except what I put in it?

My code now:

GCheckout.AutoGen.NotificationAcknowledgment response = new GCheckout.AutoGen.NotificationAcknowledgment();
response.serialnumber = serialNumber;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(GCheckout.Util.EncodeHelper.Serialize(response));
HttpContext.Current.Response.StatusCode = 200;
1
Is this WebForms? If so, is it in an .aspx page? - Michael Liu
@MichaelLiu aspx. There's no form there. it's in a callback url. - ispiro
But right now the HTTP response includes the content of the .aspx too? - Michael Liu
@MichaelLiu Well actually now that I checked again - it includes the content of the page's master page. (What I'm trying to solve is - stackoverflow.com/questions/11177384/… - perhaps it's failing because of extra stuff in the response.) - ispiro

1 Answers

2
votes

After you've set the status code and written out the response content, call HttpContext.Current.Response.End() to stop the execution of the current request.