For technical reasons we need to perform an HTTP 307 redirect instead of a 302.
For 302’s I’d do:
HttpContext.Current.Response.Redirect(url)
For 301’s I do:
HttpContext.Current.Response.RedirectPermanent(url)
How would I implement a 307?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Solved this by adding a location header and doing redirect manually:
HttpContext.Current.Response.StatusCode = 307;
HttpContext.Current.Response.StatusDescription = "Temporary Redirect";
HttpContext.Current.Response.AddHeader("Location", redirectURL);
HttpContext.Current.Response.End();
Method 2
In the page you want to cause a 307, instead of Response.Redirect use Server.Transfer: –
Server.Transfer("targetpage.aspx");
Then in Page_Load of your target page, add the following (smiley face optional): –
Response.StatusCode = 307; Response.StatusDescription = "Temporary Redirect :)";
When you view the network trace in your browser’s debug tools, this will look like the source page returned a 307. Server.Transfer does not send a response to the browser, but instead immediately transfers control to the specified page.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0