我收到异常"HTTP标头发送后无法重定向".重定向到另一个页面时 [英] I am getting exception "Cannot redirect after HTTP headers have been sent" when redirecting to another page

查看:59
本文介绍了我收到异常"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.

这篇关于我收到异常"HTTP标头发送后无法重定向".重定向到另一个页面时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆