ASP.Net中的跨域发布失去表单域 [英] Cross-Domain Posting in ASP.Net loses Form Fields

查看:362
本文介绍了ASP.Net中的跨域发布失去表单域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解决方案中的2 ASP.Net应用程序。一个是几乎是第三方应用程序的测试线程POST数据到主应用程序。我试图模仿这个功能,通过做一个基本的HTML表单和设置操作指向主应用程序;但是,Request.Form NameValueCollection为空。我试着在ASP.Net使用307重定向,我有同样的问题。我暂时将临时表单移动到主项目中,以便我可以继续测试。

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.

这是我使用的307重定向代码:

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

在ASP.net网络表单中有交叉域POSTing的方法吗?

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.

推荐答案

最简单的方法是使用非服务器侧< form>即无runat =服务器属性,只需将 操作属性设置为您要发布到的网址:

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>

希望这有帮助。

这篇关于ASP.Net中的跨域发布失去表单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆