1

I read a lost of questions and answers about cross domain post here, but I still cannot make it work. The task seems so simple, but the data I get from the receiving side is always null.

In web application 1 (sender), I have this TestCrossDomainPost.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<form action="http://localhost:55400/TestCrossDomainReceive.aspx" method="post">
    First name: <input type="text" name="fname"><br>
    Last name: <input type="text" name="lname"><br>
    <input type="submit" value="Submit">
</form>
</body>
</html>

In web application 2 (receiver), I have this TestCrossDomainReceive.aspx (nothing there):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestCrossDomainReceive.aspx.cs" Inherits="WebApplication14.TestCrossDomainReceive" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

and TestCrossDomainReceive.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication14
{
    public partial class TestCrossDomainReceive : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string fname = Request.Form["fname"];
            string lname = Request.Form["lname"];
        }
    }
}

When I set debug point in Page_Load, fname and lname are forever null

What do I miss here? I have debugged this for two days...

Community
  • 1
  • 1
alice
  • 11
  • 2
  • I can't replicate. Copying your code exactly works as expected. Can you provide more details? – MikeSmithDev Sep 15 '14 at 10:51
  • @MikeSmithDev I modified the question. That's exactly what I use; for the port number in action please change to whatever on your local machine. Thanks! – alice Sep 15 '14 at 21:49
  • Please include your `.aspx` code as well. – MikeSmithDev Sep 15 '14 at 23:42
  • OK. So following the POST, when the breakpoint is on **lname**, what is the value of **fname**? (when the breakpoint is on fname, the value hasn't been set, so yes it will be null). – MikeSmithDev Sep 16 '14 at 00:31
  • the value is null. one strange thing, at breakpoint, it shows Request.RequestType is "GET", Request.HttpMethod is "GET". but I set "post" in the sender – alice Sep 16 '14 at 00:31
  • You are checking the value of fname not when it is on fname, but when debugger is on lname? – MikeSmithDev Sep 16 '14 at 00:32
  • I can't replicate. Your code works fine for me. Perhaps there is a problem with your debugging. Try adding a label to the page, and set the `Text` of the label to the combined value of fname and lname and see if you get anything. – MikeSmithDev Sep 16 '14 at 00:50
  • I cannot believe it works for you...it absolutely doesn't work for me! – alice Sep 16 '14 at 03:36

1 Answers1

-1

The browser is generally going to stop you from doing that, for security reasons. You could:

  1. If you have control over the destination method, convert it to handle "GET" and change your POST to a GET on the source domain.

  2. POST to a proxy service on your source domain, and then have the proxy craft the POST to the destination domain.

Jonathan
  • 4,916
  • 2
  • 20
  • 37
  • You may want to read http://stackoverflow.com/questions/11423682/cross-domain-form-posting – MikeSmithDev Sep 15 '14 at 00:16
  • @MikeSmithDev, I read that post, they said we can do POST. Did I miss anyting? – alice Sep 15 '14 at 02:42
  • @Jonathan, is it weird that browser forbid this? But I can reach receiver when I click button on the sender side. If they forbid, why not just popup and tell me? Why let me go through and hit the receiver? Also, I cannot do GET since it shows everything in the query string. Can you show me how to do proxy service? I have no idea how to do it. – alice Sep 15 '14 at 02:46
  • @alice no you didn't miss anything. This answer is incorrect and no need for proxy service. It's probably an asp.net security issue. – MikeSmithDev Sep 15 '14 at 02:56
  • you don't need dot net to see the behaviour. Copy your TestCrossDomainPost into an html file. Open in Chrome. Launch Fiddler. Submit form in chrome. Inspect request in Fiddler. You will see the fname and lname parameters. Now change action in html to, say, point at Google (cross domain). Submit form. Inspect request in Fiddler. No fname / lname parameter. The reason the destination form doesn't get the parameters is because the browser isn't sending them. – Jonathan Sep 16 '14 at 14:49