我收到异常"HTTP标头发送后无法重定向".重定向到另一个页面时
问题描述:
我要例外了
"Cannot redirect after HTTP headers have been sent."
执行 Response.Redirect("Home.aspx")
时.
我该如何解决?我尝试在重定向之前提供 Response.Flush()
.
How can i solve this?
I tried giving Response.Flush()
before redirecting.
答
问题是重定向之前的 Response.Flush()
.使用HTTP,您可以收到一个响应,用于一个请求.您的浏览器只请求该页面一次,而我怀疑您正在尝试两次响应:
The problem is the Response.Flush()
prior to redirecting. With HTTP you get one response for one request. Your browser requested the page only once, and I suspect you're trying to respond twice:
Response.Flush(); //First Response
Response.Redirect("Home.aspx"); //Second Response
因此,删除此 Response.Flush()
将解决您的问题.
Therefore taking this out the Response.Flush()
will solve your problem.