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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript - Basic Response.Redirect

Status
Not open for further replies.

Sivagami

Programmer
Dec 11, 2000
14
US
Hi, I have a wierd problem. I have a basic login page, which submits to itself to verify against a database and redirects to a new page if the login is correct. I have written the same code before and this is the first time I have this problem. Here is the redirecting code :

<%if rs.EOF then
set rs=nothing
conn.Close
else
userid = rs.Fields(&quot;user_id&quot;).Value
session(&quot;Userid&quot;) = userid
set rs=nothing
conn.Close
Response.Redirect(&quot;select_trip.asp&quot;)
end if %>

It works fine when the user Input is wrong. But when the user Input is correct, instead of redirecting to &quot;Select_trip.asp&quot;, I get a &quot;Page Cannot be displayed&quot; error with the same page name in the URL. When I refresh the page, it starts from the first.

I tried replacing the VBScript Redirecting wih Javascript
document.location.href = &quot;select_trip.asp&quot;;
This also gives me the same &quot;Page Cannot be displayed&quot; error with &quot;select_trip.asp&quot; in URL, but works fine if I refresh it.

Does anyone know where I am going wrong ? Any help is greatly appreciated.

Thanks,
Shiva.
 
[tt]

Try:

Response.Redirect &quot;select_trip.asp&quot;
* * * * * * * * * * *
<%=Tony%>
cold.gif

 
Did not Help Tony.
I also have a <
%response.buffer = true %>
in the top. Does that have something to do with keeping the page busy & unavailable ? I have tried restarting the webserver, but no use.

Shiva.
 
When using Response.Redirect you can't have any data send to the user before your redirect call, otherwise you can'[t redirect. There is reasoning behind that but I can't remember what it was :p

Try killing the response.buffer line and see if that helps. Technically turning the buffer ON shouldn't cause any problems, but since it is on by default you should be ok to remove the explicit call altogether.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
This has happenned to me before and even though the same page is reflected in the address bar, the problem was always with the page I redirected to. Try connecting to select_trip.asp directly and see if the issue is there.

-John
 
Thanks for all your input.
Without explicit Response.buffer = true, I get 'Header error. HTTP headers already written to client browser' error. The select_trip.asp page does not have any probelms and works fine when connected to directly.

Shiva.
 
Basically this means some information was written to the user already, generally this is cookie informaiton or something else along those lines. Try commenting out the session(&quot;user&quot;) line just for kicks, I have an inkling og an idea but don't want to look to foolish if it is to far out in left field.
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Tarn has it right; something, however innocent was output prior to the response.redirect. Anything that's not between <% and %> and prior to the redirect would produce this result.

e.g. ...
Code:
<%option explicit%>
<!-- This is an HTML Comment -->
<%response.redirect &quot;somewhere.htm&quot;%>

... results in &quot;The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.&quot;

That's because a header of &quot;text/html&quot; gets sent to the browser whenever there is HTML text, telling the browser how to process what follows. The response.redirect is also sending a header to your browser, similar to a meta tag that redirects the browser to a different page. By the time ASP processes the redirect, it's too late.

P.S. The fact that a response.redirect goes all the way to the browser to get the user to a different page is the reason Microsoft came up with the server.transfer as a server-side (fewer round-trips) method to accomplish the same effect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top