473,287 Members | 1,663 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,287 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 24211
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.