Return 307 Temporary Redirect in ASP.NET MVC

穿精又带淫゛_ 提交于 2019-12-01 00:47:59

问题


Is it possible to return a 307 Temporary Redirect from a controller in ASP.NET MVC?

I sometimes need to re-POST the values submitted from one form to another URI.

Using JavaScript to do the selection on the client side (thereby bypassing this issue) is not an option.

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.

Is this even possible?


回答1:


Take a look at the following article - you can use the same technique for 307:

301 Redirects




回答2:


To return a 307 redirect result from an MVC action, use the following:

public ActionResult Action()
{
    string url = GetRedirectUrl()
    HttpContext.Response.AddHeader("Location", url);
    return new HttpStatusCodeResult(307);
}


来源:https://stackoverflow.com/questions/1644045/return-307-temporary-redirect-in-asp-net-mvc

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