Lets assume I have told a 3rd party to send a request to my generic handler based at {http://myIp/Myhandler.ashx}. How can I respond to the request that they send? I have the function process request which gives me access to the context object but how can this be used to ensure my response goes back to the same place that the request originated from and thus acting as a reply to their request. I tried constructing an HTTPResponse object and sending it to their server but this did not work. I am trying to reply to them with an OK message and give them a web address to redirect the user to.
public void ProcessRequest(HttpContext context)
{
string status = context.Request.Params["Status"];
string statusDetail = context.Request.Params["StatusDetail"];
switch (status.ToUpper())
{
case "OK":
{
StringBuilder content = new StringBuilder();
content.Append("Status=" + HttpUtility.UrlEncode("OK"));
content.Append("&RedirectURL=" + HttpUtility.UrlEncode("http://http://myip:myport/Error.aspx?Error=SUCCESS"));
content.Append("&StatusDetail=" + HttpUtility.UrlEncode("OK"));
HttpWebResponse response = SendPOSTRequest("http://theirip.page", content.ToString(), "", "", true);
}
}
Use the
contextparameter to setup the response to be sent. Since your response is a string, you can just useWrite:You’ll also want to set some of the response headers: