redirect on the home page

S

shank

I have the following code to redirect users to
http://www.mydomain.com/new/default.asp if they use the URL www.newstuff.com
(sample). I have that domain name parked on www.mydomain.com. I'm getting
the follwing error...

Response object error 'ASP 0156 : 80004005'
Header Error
/Default.asp, line 21 <--- this is my home page
The HTTP headers are already written to the client browser. Any HTTP header
modifications must be made before writing page content.

Can anyone give me a clue?
thanks!

<%
sname = UCASE(Request.ServerVariables("SERVER_NAME"))
If InStr(sname,"NEWSTUFF") <> 0 then
response.redirect "http://www.mydomain.com/new/"
End If
%>
 
R

Ray at

You cannot redirect if you have already sent data to the client, for
example:

<html>
<head>
<title>a page</title>
<% response.redirect "somewhereelse" %>

You have to either put your redirect prior to any html or any header
writing, or turn on buffering. I'll assume you're on NT4, since buffering
is off by default in IIS4. Or, you have buffering turned off. You can
enable buffering for your page by doing:

<%
response.buffer = true %>

That will hold all html in a buffer until the page is finished processing.

Ray at work
 
S

shank

Ray at said:
You cannot redirect if you have already sent data to the client, for
example:

<html>
<head>
<title>a page</title>
<% response.redirect "somewhereelse" %>

You have to either put your redirect prior to any html or any header
writing, or turn on buffering. I'll assume you're on NT4, since buffering
is off by default in IIS4. Or, you have buffering turned off. You can
enable buffering for your page by doing:

<%
response.buffer = true %>

That will hold all html in a buffer until the page is finished processing.

Ray at work

This is my first 3 lines...
When I added the buffer statement, the home page (default.asp) would not
load at all.
Am I missing something?
thanks!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<%@LANGUAGE="VBSCRIPT"%>
<% response.buffer = true %>
 
R

Ray at

shank said:
This is my first 3 lines...
When I added the buffer statement, the home page (default.asp) would not
load at all.
Am I missing something?
thanks!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

That first line looks like client response to me.
<%@LANGUAGE="VBSCRIPT"%>
<% response.buffer = true %>

You won't see anything if this is all your page is.

What are you trying to do? What I'm saying is if you choose to use
response.redirect, you cannot use it if you have already sent any response
to the client. So, you either have to turn on buffering at the top of your
page, or you have to redirect at the top of your page.

Ray at work
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top