首页 > 解决方案 > 执行 HTTP 307 重定向

问题描述

出于技术原因,我们需要执行 HTTP 307 重定向而不是 302。

对于 302,我会这样做:

HttpContext.Current.Response.Redirect(url)

对于 301,我这样做:

HttpContext.Current.Response.RedirectPermanent(url)

我将如何实施 307?

标签: c#asp.netredirect

解决方案


通过添加位置标头并手动执行重定向来解决此问题:

                    HttpContext.Current.Response.StatusCode = 307;
                    HttpContext.Current.Response.StatusDescription = "Temporary Redirect";
                    HttpContext.Current.Response.AddHeader("Location", redirectURL);
                    HttpContext.Current.Response.End();

推荐阅读