473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cannot redirect after http headers have been sent

Hello,

I get this error Message "cannot redirect after http headers have been sent"
when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sent like

If response.IsSentHttpHeader then
....
End If.

Thanks for any help in advance!
Andreas Klemt
Nov 18 '05 #1
8 24232
I always ask a question. How many pages have this problem?

chanmm

"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
Hello,

I get this error Message "cannot redirect after http headers have been sent" when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sent like

If response.IsSentHttpHeader then
...
End If.

Thanks for any help in advance!
Andreas Klemt

Nov 18 '05 #2
chanmmn, do you have a solution?
"chanmmn" <ch*****@hotmail.com> schrieb im Newsbeitrag
news:%2*****************@TK2MSFTNGP12.phx.gbl...
I always ask a question. How many pages have this problem?

chanmm

"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
Hello,

I get this error Message "cannot redirect after http headers have been

sent"
when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sent like
If response.IsSentHttpHeader then
...
End If.

Thanks for any help in advance!
Andreas Klemt


Nov 18 '05 #3

Andreas Klemt wrote:
*Hello,

I get this error Message "cannot redirect after http headers hav
been sent"
when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sen
like

If response.IsSentHttpHeader then
.....
End If.

Thanks for any help in advance!
Andreas Klemt *


Hi

Are you writing anything out to the Response stream prior to callin
Redirect;

eg.

Response.Write("this is a test");
//some more code...
Response.Redirect(strNewASPPage);

If so the first Response.Write will send a response to request heade
to the browser.

If you then call Response.Redirect, you are sending a different heade
to the browser. This is an error. You can't send two different header
to the browser
-
spaldin
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 18 '05 #4
I have this problem also.

And yes, I believe that is exactly how it is caused.

The question now is:
how do I detect this condition?

I have used Try Catch to eat the exception and this does not work reliably
either.
I usually end up in my Global error handler and any attempt th re-direct to
my custom error page causes this exception. It is quite frustrating.

I believe the cause is using Ben Lowery's httpCompression module. This is an
excellent module for compressing data sent over the wire but when I get an
error and try to re-direct to my custom page it is "too late" because the
Headers have been sent by the compression module.

I would dearly love a solution to this issue as otherwise I may have to
remove the compression feature.

--
Joe Fallon

"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...

Andreas Klemt wrote:
*Hello,

I get this error Message "cannot redirect after http headers have
been sent"
when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sent
like

If response.IsSentHttpHeader then
.....
End If.

Thanks for any help in advance!
Andreas Klemt *


Hi

Are you writing anything out to the Response stream prior to calling
Redirect;

eg.

Response.Write("this is a test");
//some more code...
Response.Redirect(strNewASPPage);

If so the first Response.Write will send a response to request header
to the browser.

If you then call Response.Redirect, you are sending a different header
to the browser. This is an error. You can't send two different headers
to the browser.

--
spalding
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 18 '05 #5
Try Response.ClearContents and ClearHeaders. If all else fails, do a client
side window.location.replace or navigate - with a registerclientscript on
server side.

Sekhar.
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
I have this problem also.

And yes, I believe that is exactly how it is caused.

The question now is:
how do I detect this condition?

I have used Try Catch to eat the exception and this does not work reliably
either.
I usually end up in my Global error handler and any attempt th re-direct to my custom error page causes this exception. It is quite frustrating.

I believe the cause is using Ben Lowery's httpCompression module. This is an excellent module for compressing data sent over the wire but when I get an
error and try to re-direct to my custom page it is "too late" because the
Headers have been sent by the compression module.

I would dearly love a solution to this issue as otherwise I may have to
remove the compression feature.

--
Joe Fallon

"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...

Andreas Klemt wrote:
*Hello,

I get this error Message "cannot redirect after http headers have
been sent"
when I do this
response.redirect ("home.aspx")

How can I find out with vb.net if already a http header has been sent
like

If response.IsSentHttpHeader then
.....
End If.

Thanks for any help in advance!
Andreas Klemt *


Hi

Are you writing anything out to the Response stream prior to calling
Redirect;

eg.

Response.Write("this is a test");
//some more code...
Response.Redirect(strNewASPPage);

If so the first Response.Write will send a response to request header
to the browser.

If you then call Response.Redirect, you are sending a different header
to the browser. This is an error. You can't send two different headers
to the browser.

--
spalding
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------


Nov 18 '05 #6

Hi Joe and Andreas

In what way are you using Response.Write and Response.Redirect at th
same time?

Joe, you mentioned that you were using a compression class to outpu
your data. Does it use the Response object in any way?

Would you be able to post a code snippet so we can see exactly how you
code is structured?

Chandra Sekhar has suggested a good solution; ClearHeaders o
ClearContent. Just make sure BufferOutput is true (it is by default).
Javascript redirect is good but you don't know if it is disabled on th
client (and with many recent security issues it may be).

Alternatively, write your output to a string variable then use a
if...else statement for calling either Response.Write o
Response.Redirect.

Joe Fallon wrote:
*I have this problem also.

And yes, I believe that is exactly how it is caused.

The question now is:
how do I detect this condition?

I have used Try Catch to eat the exception and this does not wor
reliably
either.
I usually end up in my Global error handler and any attempt t
re-direct to
my custom error page causes this exception. It is quite frustrating.

I believe the cause is using Ben Lowery's httpCompression module
This is an
excellent module for compressing data sent over the wire but when
get an
error and try to re-direct to my custom page it is "too late" becaus
the
Headers have been sent by the compression module.

I would dearly love a solution to this issue as otherwise I may hav
to
remove the compression feature.

--
Joe Fallon

"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...

Andreas Klemt wrote:

Hi

Are you writing anything out to the Response stream prior t

calling
Redirect;

eg.

Response.Write("this is a test");
//some more code...
Response.Redirect(strNewASPPage);

If so the first Response.Write will send a response to reques

header
to the browser.

If you then call Response.Redirect, you are sending a differen

header
to the browser. This is an error. You can't send two differen

headers
to the browser.

--
spalding


------------------------------------------------------------------------
Posted via http://www.codecomments.com


------------------------------------------------------------------------

-
spaldin
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 18 '05 #7
========================================
The source for the compression module is located here:
http://www.blowery.org/code/HttpCompressionModule.html

Note: Ben Lowery fiixed the code 4 months ago to work with Server.Transfer
and Response.Redirect.
I think my case is not part of his fix.

/// An HttpModule that hooks onto the Response.Filter property of the
/// current request and tries to compress the output, based on what
/// the browser supports.

///This module checks the Accept-Encoding HTTP header to determine if the
/// client actually supports any notion of compression. Currently, we
support
/// the deflate (zlib) and gzip compression schemes.
========================================
When I have it enabled in my web.config, the pages are sent to the browser
in compressed form.
But the module must be sending the headers "early" in the process. When I
run into an unhandled error, I log it and clear it in Global.asax and then
re-direct to my custom error form. This re-direct is what causes the dreaded
"http headers have already been sent" error. I am using a Try catch block
around my re-direct in Global.asax in an attempt to "eat the error".
========================================
I tried the settings ClearHeaders or ClearContent. But it did not stop the
error from occurring.
========================================
In Global.asax I have this: (remember, I was trying to load a page and got
an unhandled error)
========================================
'log error here. Then:

Server.ClearError()

'JF 8/9/2004 - See if this will prevent the error for "Server cannot append
header after HTTP headers have been sent." Nope.
Response.ClearContent()
Response.ClearHeaders()

Dim strErrorMessage As String = "We're sorry, but an unhandled error
occurred on the server. The Server Administrator has been notified and the
error logged."

Try
'this shared method sets some variables and then re-directs to my
standard error page.
MyUtilClass.DisplayErrorMessage("Application Error", strErrorMessage)
Catch except As Exception
'do nothing
End Try
========================================

Thanks for any advice.
--
Joe Fallon


"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...

Hi Joe and Andreas

In what way are you using Response.Write and Response.Redirect at the
same time?

Joe, you mentioned that you were using a compression class to output
your data. Does it use the Response object in any way?

Would you be able to post a code snippet so we can see exactly how your
code is structured?

Chandra Sekhar has suggested a good solution; ClearHeaders or
ClearContent. Just make sure BufferOutput is true (it is by default). A
Javascript redirect is good but you don't know if it is disabled on the
client (and with many recent security issues it may be).

Alternatively, write your output to a string variable then use an
if...else statement for calling either Response.Write or
Response.Redirect.

Joe Fallon wrote:
*I have this problem also.

And yes, I believe that is exactly how it is caused.

The question now is:
how do I detect this condition?

I have used Try Catch to eat the exception and this does not work
reliably
either.
I usually end up in my Global error handler and any attempt th
re-direct to
my custom error page causes this exception. It is quite frustrating.

I believe the cause is using Ben Lowery's httpCompression module.
This is an
excellent module for compressing data sent over the wire but when I
get an
error and try to re-direct to my custom page it is "too late" because
the
Headers have been sent by the compression module.

I would dearly love a solution to this issue as otherwise I may have
to
remove the compression feature.

--
Joe Fallon

"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...
>
> Andreas Klemt wrote:
>
> Hi
>
> Are you writing anything out to the Response stream prior to

calling
> Redirect;
>
> eg.
>
> Response.Write("this is a test");
> //some more code...
> Response.Redirect(strNewASPPage);
>
> If so the first Response.Write will send a response to request

header
> to the browser.
>
> If you then call Response.Redirect, you are sending a different

header
> to the browser. This is an error. You can't send two different

headers
> to the browser.
>
>
>
> --
> spalding
>

------------------------------------------------------------------------
> Posted via http://www.codecomments.com
>

------------------------------------------------------------------------
> *


--
spalding
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 18 '05 #8

Hi Joe

Apologies for not getting back to you sooner.

Okay;

Response.ClearHeaders and Response.ClearContents will only work i
Response.BufferOutput is true (which is by default). In fact, i
BufferOutput is set to false, the Response object will send data to th
browser immediately on every call.

Does your code set the BufferOutput field to false?
eg. Response.BufferOutput = false;

If so, you will not be able to call Write and then call Redirect in th
same code block.

If the compression utility is doing it, then you will need to hack th
above change out of it.

However, the problem does not occur with Server.Transfer()
Joe Fallon wrote:
*========================================
The source for the compression module is located here:
http://www.blowery.org/code/HttpCompressionModule.html

Note: Ben Lowery fiixed the code 4 months ago to work wit
Server.Transfer
and Response.Redirect.
I think my case is not part of his fix.

/// An HttpModule that hooks onto the Response.Filter property o
the
/// current request and tries to compress the output, based on what
/// the browser supports.

///This module checks the Accept-Encoding HTTP header to determine i
the
/// client actually supports any notion of compression. Currently
we
support
/// the deflate (zlib) and gzip compression schemes.
========================================
When I have it enabled in my web.config, the pages are sent to th
browser
in compressed form.
But the module must be sending the headers "early" in the process
When I
run into an unhandled error, I log it and clear it in Global.asax an
then
re-direct to my custom error form. This re-direct is what causes th
dreaded
"http headers have already been sent" error. I am using a Try catc
block
around my re-direct in Global.asax in an attempt to "eat the error".
========================================
I tried the settings ClearHeaders or ClearContent. But it did no
stop the
error from occurring.
========================================
In Global.asax I have this: (remember, I was trying to load a pag
and got
an unhandled error)
========================================
'log error here. Then:

Server.ClearError()

'JF 8/9/2004 - See if this will prevent the error for "Server canno
append
header after HTTP headers have been sent." Nope.
Response.ClearContent()
Response.ClearHeaders()

Dim strErrorMessage As String = "We're sorry, but an unhandled error
occurred on the server. The Server Administrator has been notifie
and the
error logged."

Try
'this shared method sets some variables and then re-directs to my
standard error page.
MyUtilClass.DisplayErrorMessage("Application Error"
strErrorMessage)
Catch except As Exception
'do nothing
End Try
========================================

Thanks for any advice.
--
Joe Fallon


"spalding" <sp*************@mail.codecomments.com> wrote in message
news:sp*************@mail.codecomments.com...

Hi Joe and Andreas

In what way are you using Response.Write and Response.Redirect a

the
same time?

Joe, you mentioned that you were using a compression class t

output
your data. Does it use the Response object in any way?

Would you be able to post a code snippet so we can see exactly ho

your
code is structured?

Chandra Sekhar has suggested a good solution; ClearHeaders or
ClearContent. Just make sure BufferOutput is true (it is b

default). A
Javascript redirect is good but you don't know if it is disabled o

the
client (and with many recent security issues it may be).

Alternatively, write your output to a string variable then use an
if...else statement for calling either Response.Write or
Response.Redirect.

Joe Fallon wrote:

--
spalding


------------------------------------------------------------------------
Posted via http://www.codecomments.com

------------------------------------------------------------------------
*


--
spalding
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dariusz | last post by:
I have a problem where when I run the PHP code offline, there are no errors produced and the code runs as expected. However when I uploaded the same script and run it, it says the headers have...
5
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
1
by: chsakda | last post by:
In my Page_Load Method, I call a method by asynchronous callback to do some work. It's working fine until it calls back. Here is the problem in my callback method. Basically, I cannot redirect...
0
by: Hai Nguyen | last post by:
Hi everyone I have a progressive bar which is outputted by Response.Write("javascript code") and Response.Flush() After the progressive bar reach 100% I want to redirect this page to my main...
6
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
4
by: craigtomo | last post by:
I am getting the following error when i try to log on to my data base Warning: session_register() : Cannot send session cookie - headers already sent by (output started at...
11
by: craigtomo | last post by:
i have changed my login .php file to the following this file is opened directly and is not called from any other file <?php // dBase file $host=""; // Host name $username=""; // Mysql...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.