Question

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());
    }
Was it helpful?

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

OTHER TIPS

You can generate JSON from your HTTP Handler and use jquery.post to submit form data and get results in the ColdFusion page.

If you want ColdFusion to know what is being returned, then there are really two ways to go about it.

The first is to return the string to the form (as suggested by womp) and then handle it from the browser, either by submitting a secondary form or some other means. Since it looks like all the values in the form are being provided instead of user-supplied, this is not what I would do.

A second method would be for CF to handle the form post itself. Assuming that the values being passed by your form are available to CF, you can use CFHTTP to "fake" a form post. CF would be returned the result directly, and you could handle the response from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top