我正在尝试进行 HTTP 302 重定向,但在 Debug模式下运行时出现以下异常。
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
var response = HttpContext.Current.Response;
response.Clear();
response.Status = "302 Found";
response.AddHeader("Location", "http://google.com");
response.End();
response.Flush();
长话短说,此调用不会刷新响应也不会重定向。
我怎样才能让它工作?
最佳答案
您不应该以这种方式同时调用 End
和 Flush
- 要使用 HTTP 302 重定向,您应该使用 HttpContext.Current.Response.Redirect
参见 http://msdn.microsoft.com/en-us/library/a8wa7sdt.aspx
关于c# - HTTP 重定向 302,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7233692/