Is it possible to return a 307 Temporary Redirect
from a controller in ASP.NET MVC?
是否可以从ASP.NET MVC中的控制器返回307临时重定向?
I sometimes need to re-POST
the values submitted from one form to another URI.
我有时需要将从一个表单提交的值重新POST到另一个URI。
Using JavaScript to do the selection on the client side (thereby bypassing this issue) is not an option.
使用JavaScript在客户端进行选择(从而绕过此问题)不是一种选择。
Redirecting via a GET
is not an option as posted data includes an 8k string which is likely to mean that the URI would be too long for some (many?) browsers.
通过GET重定向不是一个选项,因为发布的数据包含一个8k字符串,这可能意味着URI对于某些(很多?)浏览器来说太长了。
Is this even possible?
这有可能吗?
2 个解决方案
#1
2
Take a look at the following article - you can use the same technique for 307:
看看下面的文章 - 您可以使用相同的技术307:
#2
9
To return a 307 redirect result from an MVC action, use the following:
要从MVC操作返回307重定向结果,请使用以下命令:
public ActionResult Action()
{
string url = GetRedirectUrl()
HttpContext.Response.AddHeader("Location", url);
return new HttpStatusCodeResult(307);
}
#1
2
Take a look at the following article - you can use the same technique for 307:
看看下面的文章 - 您可以使用相同的技术307:
#2
9
To return a 307 redirect result from an MVC action, use the following:
要从MVC操作返回307重定向结果,请使用以下命令:
public ActionResult Action()
{
string url = GetRedirectUrl()
HttpContext.Response.AddHeader("Location", url);
return new HttpStatusCodeResult(307);
}