2

I've got two scripts on a windows server, setup to receive data from a post.

One is a PHP file that works.

<?php   
echo "Hello! <br/> This is a Post Back script that writes to a text file!";

// retrieving information from Post Back
$accounting         = $_POST["accountingAmount"];
$accounting_txt     = "accounting: " . "$accounting" . "\n\n";
$address1           = $_POST["address1"];

// LOTS MORE FIELDS //

$address1_txt       = "address1: " . "$address1" . "\n\n";
"$recurPrice_txt" . "$referer_txt" . "$referringUrl_txt" . "$reservationId_txt" . "$responseDigest_txt" . "$start_date_txt" . "$state_txt" . "$sub_id_txt" . "$typId_txt" . "$username_txt" . "$zipcode_txt";

// write to a text file
$myFile = "postback.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $message;
fwrite($fh, $stringData);
fclose($fh);
?>

The ASP.NET MVC script is this:

[HttpPost]
    public ActionResult approved(FormCollection formValues)
    {           
            var context = new LSmixDbEntities();
            PaymentHistory ph = new PaymentHistory();
            StringBuilder s = new StringBuilder();
            foreach (string key in Request.Form.Keys)
            {
                s.AppendLine(key + ": " + Request.Form[key] + Environment.NewLine);
            }
            string formData = s.ToString();
    //save formData in db
    }

I tested by putting vs on the server itself and breakpointing, the action doesn't even start.

Is there any reason a .php file would be hit by a remote postback, but an MVC action wouldn't be?

Chris Barry
  • 4,564
  • 7
  • 54
  • 89

1 Answers1

1

The PHP script doesn't have any HTTP Method guards - it would be run in a GET or a POST request, whereas the MVC engine only fires the approved method in response to a POST request (because you have the [HttpPost] attribute). I'm guessing you're just hitting your server with your web-browser (which would always fire a GET request) instead of using a tool to create a POST request.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thanks, but I'm definitely hitting it with a post. I've now had the same problem using a straight .aspx file, so the journey continues – Chris Barry Nov 28 '12 at 23:22
  • What happens when you call `phpinfo();` ? – Dai Nov 28 '12 at 23:34
  • This is a new question which is more specific. You can see the request hitting the server, and then returning a 500. http://stackoverflow.com/questions/13627057/error-when-receiving-post-from-libwww-perl-to-iis-asp-net – Chris Barry Nov 30 '12 at 01:11