Cross-Domain Posting in ASP.Net loses Form Fields

偶尔善良 提交于 2019-12-11 17:13:22

问题


I have 2 ASP.Net applications in a solution. One is pretty much a testing harness for a 3rd party app that POSTs data into the primary application. I tried to mimic this functionality by doing a basic HTML form and setting the action to point to the main application; however, the Request.Form NameValueCollection was empty. I tried doing it in ASP.Net using a 307 redirect and I had the same issue. I temporarily have moved the temp form into the main project so I can continue testing.

Here is the 307 Redirect code that I was using:

Response.ClearContent();
Response.StatusCode = 307;
Response.StatusDescription = "Temporary Redirect";
//redirect to a different app.
Response.RedirectLocation = "http://localhost:xxxx/default.aspx";
Response.Flush();

Is there a way to do cross domain POSTing in ASP.net web forms? It works in the same domain but not different domains for some reason.


回答1:


The easiest way would be to use a non-server-side <form> i.e. with no runat="server" attribute, and just set the action attribute to the URL you want to post to:

<form method="post" action="http://localhost:xxxx/default.aspx">
    ...
</form>

Hope this helps.



来源:https://stackoverflow.com/questions/1188266/cross-domain-posting-in-asp-net-loses-form-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!