Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting

Status
Not open for further replies.

rondavid

Programmer
Apr 29, 2003
19
US
Hello everyone, Question I have an asp page that when you submit a form the information gets emailed to xyz company, but then I am trying to redirect the page to an html page using response.redirect and I keep getting the following error: HTTP Header already written to client browser. This is after the rest of the code runs fine. It's crashing at the redirect. Alternatives?
 
Response.Redirect must be used before any <html> tags in the page or you will receive the error you mention.

With that said [red]Don't use it![/red]

User Server.Transfer() instead it does not cause a round trip between the browser and server.


-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
Palbano thanks for the help but What is server.transfer(), there is no method called transfer for the server object. If there is MS InterDev does not display it and what are the arguments you pass to the method.
 
You use it the same as Response.Redirect
ie
Server.Transfer <new page name>

Things to note:
1. From memory it carries over form/querystring variables from the page which calls the Server.Transfer method.
2. To all intents and purposes it's still named the first page (the page which calls the Server.Transfer method) - this can cause hassles if you have code which needs the real page name.
3. Also from memory, Server.Transfer is one-way; there is also Server.Execute which is like Server.Transfer except it returns execution to the calling page upon completion. NOTE there is no sharing of variables/code/objects/etc between the pages with Server.Execute.
4. I think Server.Transfer doesn't allow passing [new] querystring variables along with the transfer
ie Server.Transfer b.asp?c=d won't work from memory.

.. and yes it doesn't appear in InterDev for whatever reason .. guess they forgot to update the help files, or it was added after they were produced, or some such.

codestorm
Fire bad. Tree pretty. - Buffy
Kludges are like lies.
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
rondavid,

Do not rely on IntelliSense. Go to the Platform SDK for windows. In Java read the SDK Javadocs for the Java API's. I don’t care what product you are using… don’t do it.

[red]Never rely on IntelliSense[/red] to provide you with your knowledge of a SDK or API.

Also don’t rely on IntelliSense.

[sub]don’t rely on IntelliSense[/sub]
[hammer]

;-)



-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
Thanks for the help everyone. But when I use Server.Transfer I property or method doesnt exist for the object. Maybe there was a misunderstanding. My server script is written is VBScript. But Server.Transfer always gives me the above error. Thanks
 
I guess it depends on the version of IIS you're running .. it probably doesn't exist for PWS, or IIS less than 4 or so ..

codestorm
Fire bad. Tree pretty. - Buffy
Kludges are like lies.
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
>> I guess it depends on the version of IIS you're
>> running .. it probably doesn't exist for PWS, or IIS
>> less than 4 or so ..

Yes, they hide those facts in the documentation.
[hammer]

rondavid
When crossing posts with people in forums you don't know what their background is. My advice would be that you learn to read the documentation for the systems you are developing with. It really makes things much easier. Developing quality software is difficult enough without mixing in guessing and assumption techniques.

Is there a specific reason you are not running on an IIS 5 or greater platform?


-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
If you want to send the email and redirect the user immediately, you don't need any html, or you can do all this at the top of the page before any HTML is written.

If, as I guess, you have a &quot;Thank you for filling the form in&quot; page, why not just use a hyperlink for the user to continue and/or a meta refresh within your <HEAD> tags to redirect the user after a number if seconds.

<meta http-equiv=&quot;refresh&quot; content=&quot;10; URL=newpage.asp&quot;>

...will redirect the user to &quot;newpage.asp&quot; after 10 seconds

BDC.
 
HI rondavid,

U mighe be flushing the content before redirecting the page using response.flush. This will write the headers and will not allow to use the response.redirect.

if you are not using the response.flush anywhere before Redirecting then just use :

response.clear and then response.redirect (&quot;URL&quot;)

This will solve your problem

Hope this helped you!

Regards,
Srinu
 
thanks for all the help guys, but the server is running IIS 5. I like your ideas !!!
 
palbano/codestorm, I'm curious why not to use the response.redirect? I'm programming on an intranet and we use it quite a bit. I also had never heard of the server.transfer. a lot of our redirects do carry data back in the url tho so it doesn't sound like (based on the limitations mentioned above) it would work for most of our pages. is the main reason not to use it more related to internet programming?
mb

&quot;Where's the Ka-Boom? There's supposed to be an Earth-shattering Ka-Boom!&quot;
Marvin the Martian
 
It's just as palbano mentioned, that Response.Redirect sends a message back to the browser telling it to request the new page. That request is then sent back to the server, which in turn serves up the second page. If you're concerned with site speed, or excessively concerned about bandwidth, it can be a hassle.

/Slightly/ less hassle between MS IIS and MSIE though, as they cheat with their communications between each other anyway.

codestorm
Newbie Life Member.
Fire bad. Tree pretty. - Buffy
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top