Best way to return a string from an HTTPHandler to a page that POSTs this .ashx file

asp.net, c#, coldfusion, httphandler, post

Solution

Just write the string directly to the response object in your ProcessRequest method.

public void ProcessRequest(System.Web.HttpContext context)
{
    context.Response.Write(mystring);
}

Problem

I have an ASP.Net HTTPHandler that gets POSTed from a ColdFusion web page whose FORM looks something like: ``` <form name="sendToHandler" action="http://johnxp/FileServiceDemo2005/UploadHandler.ashx" method="post"> <input type="hidden" name="b64fileName" value="fileservice.asmx.xml" /> <input type="hidden" name="strDocument" value="Document" /> <input type="submit" name="submitbtn" value="Submit" /> ``` What is the best way for this .Net Handler to return a string to the POSTing ColdFusion page? EDIT update Aug 14, 2009: The solution I came up in my .ashx file involves saving the URL of the .cfm file that POSTed my handler and appending a querystring with the result string(s) that I want to communicate back to ColdFusion. My CF colleague uses the presence or absence of this querystring data to format the .cfm webpage accordingly: ``` public void ProcessRequest(HttpContext context) { string returnURL = context.Request.ServerVariables["HTTP_REFERER"]; // posting CFM page string message = UploadFile(context); // handles all the work of uploading a file StringBuilder msgReturn = new StringBuilder(returnURL); msgReturn.Append("?n="); msgReturn.Append(HttpUtility.UrlEncode(TRIMrecNumAssigned)); msgReturn.Append("&m="); // this is just a msg with performance data about the upload operation (elapsed time, size of file, etc.) msgReturn.Append(HttpUtility.UrlEncode(message)); context.Response.Redirect(msgReturn.ToString()); } ```

Original source