将表单重新发布到不同的操作(不是来自我的网站)并添加其他数据
我想这样做是因为我需要发布到国外网站,并且希望避免在表单内设置隐藏输入,因为用户可能会更改其中的值(或者其他人可能会为他这样做)
我的html :
<form action="<%=Url.Action("prepare") %>" >
<input type="submit" value="submit" />
</form>
和我的行动
[HttpPost]
public ActionResult Prepare()
{
if(Request.IsAuthenticated)
{
//post to "http://example.com/do"
//and add to the request userId = User.Identity.Name
return //the result of the repost
}
else
{
return RedirectToAction("youneedtobeloggedin",);
}
}
I would like to do this because I need to post to a foreign site, and would like to avoid setting a hidden input inside the form because the user might change the value inside of it (or somebody else might do it for him)
my html:
<form action="<%=Url.Action("prepare") %>" >
<input type="submit" value="submit" />
</form>
and my Action
[HttpPost]
public ActionResult Prepare()
{
if(Request.IsAuthenticated)
{
//post to "http://example.com/do"
//and add to the request userId = User.Identity.Name
return //the result of the repost
}
else
{
return RedirectToAction("youneedtobeloggedin",);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想将所有内容保留在服务器端,可以查看此处。这是一种以编程方式执行 POST 的简单方法。通过这种方式,您将在所有服务器端处理外部 POST。请注意,这将使您的服务器执行 POST。
在您的控制器中,您可以执行以下操作:
HttpPost 是您可以在我的链接中找到的函数。
If you want to keep everything server side, you can take a look at here. It's a simple way to perform POSTs programmatically. In this way you'll handle external POSTs all server side. Please beware that this will make your server perform the POST.
In your controller you can have this Action:
The HttpPost is the function you can find in my link.
现代浏览器不允许跨站点调用。因为安全。
Cross-site calls are not allowed by modern browsers. Because of security.