4

Is it possible to post data from an asp.net application in one domain to another application on a different domain?

I've seen some of the posts where people mention some rather strange ways to inject forms into the response stream, but this seems overkill.

Is it possible and what is the best way to achieve it without hacking Asp.net to death?

Thanks, Jacques

Jacques
  • 6,936
  • 8
  • 43
  • 102

2 Answers2

4

It's absolutely possible, and pretty easy to do.

  1. Browser posts data to your .net app
  2. Your app uses the HttpWebRequest object to post data to the 3rd party site
  3. 3rd party site gives data back to your app or simply accepts post.
  4. Your app responds to the browser with whatever you need.

I have no idea why you would "inject forms into the response stream" or do anything funky like that. Perhaps you could add a bit more about your requirements.

Chris.

NotMe
  • 87,343
  • 27
  • 171
  • 245
  • Hi Chris, it's actually as simple as you say. Our client's website uses a 3rd party quotation tool which is another asp.net based application. Essentially our site will get some input from the user and push it to the other application with a simple post. – Jacques Aug 30 '11 at 15:09
  • Yea.. but how do you post and redirect to that page.. like native form. If i do this my target page gets the post data.. then i redirect and the post data is gone.(two httprquests) In php it simple to go to another domains page with post data.. in net it seems impossible> – Piotr Kula Jun 19 '12 at 11:43
  • @ppumkin: Of course the post data will be gone in a redirect. All a redirect does is tell the browser to `GET` the new page. You might want to read this: http://stackoverflow.com/questions/6062078/response-redirect-which-posts-data-to-another-url-in-asp-net Incidentally, this is the exact same approach that you would have to take with PHP. – NotMe Jun 19 '12 at 14:04
  • Yea after a few hours i came to realise that. I have changed my approach to use jQuery to handle what I need. Just seems easier in the long run for more possibilities. Thanks anyway :-) +1 – Piotr Kula Jun 19 '12 at 14:08
3

If you have access to both applications then the best way is to do it server side.

So make a web service available and consume it from the posting application.

or

Use httpwebrequest server side, see link below.

http://www.netomatix.com/httppostdata.aspx

On the client you could use a library such as http://easyxdm.net/wp/ - though there is a bit of a learning curve.

Here are a couple of links that may help you if you dont want to use the above routes and are prepared to edit your asp.net pages.

http://blog.dmbcllc.com/2009/11/11/asp-net-cross-domain-form-submission/

Cross-Domain Posting in ASP.Net loses Form Fields

Community
  • 1
  • 1
WooHoo
  • 1,912
  • 17
  • 22
  • Isn't this just simply a case of setting up the HTML form to post to the other application/domain? – Jacques Aug 30 '11 at 11:50
  • If you do it server side you bypass the cross domain issue, if you use a library like easyxdm then it will use a combination of methods to transport the data client side. You could also look at doing a httpwebrequest server side. – WooHoo Aug 30 '11 at 11:57