Why HttpResponse.AppendHeader does not apply if Redirect is used?

  • Thread starter newsgroup.poster
  • Start date
N

newsgroup.poster

I need to set a custom http header before perform http redirection.

I do

response.AppendHeader("aCustomHeader", "aCustomValue")
response.Redirect("anUrl")

and my added header doesn't show up, it seems to be erased, if I
remove the redirect, it does.

Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
library/t9dwyts4.aspx) it doesn't explain why the behaviour is
occuring.

How can I workarround this issue?

Am I forced to implement my own redirect?

Thanks,

Gauthier Segay
 
D

Damien

I need to set a custom http header before perform http redirection.

I do

response.AppendHeader("aCustomHeader", "aCustomValue")
response.Redirect("anUrl")

and my added header doesn't show up, it seems to be erased, if I
remove the redirect, it does.

Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
library/t9dwyts4.aspx) it doesn't explain why the behaviour is
occuring.

How can I workarround this issue?

Am I forced to implement my own redirect?

Thanks,

Gauthier Segay

There is a clue in the documentation, under Exceptions:

HttpException A redirection is attempted after the HTTP
headers have been sent

So I think you're going to have to set the RedirectLocation property
and choose an appropriate status to send.

Damien
 
B

bruce barker

a Response.Redirect clears all content. you will need to write your own
redirect.

-- bruce (sqlwork.com)
 
N

newsgroup.poster

Thanks to both for your replies, I've added a comment to the msdn
library

if anyone have pointers to some freely usable implementation of
redirect that allows more flexibility, that would be of great use.

In the mean time I've hacked something simpler for my limited usecase.
 
G

George

To do redirect you need to do 4 lines of code.

Request.Status = "302 Moved Permanently";
Request.StatusCode = 302;
Request.AddHeader("Location", sUrl);
rq.End();

George.

Thanks to both for your replies, I've added a comment to the msdn
library

if anyone have pointers to some freely usable implementation of
redirect that allows more flexibility, that would be of great use.

In the mean time I've hacked something simpler for my limited usecase.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top