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

Problems with Redirect Statement 1

Status
Not open for further replies.

AllenRitch

Technical User
May 20, 2003
52
US
Below is the code I am using and the include statement contains both the database & recordset createobject statements (among other things). I recieve no erros, and everything works except for the response.redirect statements found near the bottom just befor the VBScript Error Checker. Why not? Thanks...

<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<!-- Make Data Connection -->
<!--#include file=includes\DataConn.inc -->
<%
On Error Resume Next

' Declare User & General Variables
Dim UserAlias, ReturnCode, UserFound

' Get User's Alias
UserAlias = Right(request.ServerVariables(&quot;logon_user&quot;),4)
ReturnCode = Len(UserAlias)

' Validate & Check the Alias against the database for further processing.
If ReturnCode<>4 Then
' Invalid Alias
response.redirect &quot;error.htm&quot;
Else
' Valid Alias; See if Alias already exists in table.
SQLString = &quot;SELECT * FROM [tblAlias] WHERE user_alias='&quot; & UserAlias & &quot;';&quot;
RDSet.Open SQLString, DBConn

If RDSet.EOF Then
' Alias doesn't exist
UserFound = &quot;False&quot;
Else
' Alias does exist
UserFound = &quot;True&quot;
End If

' Close Record Set
RDSet.Close
Set RDSet = Nothing
End If

' Check for Database Errors before closing
If DBConn.Errors.Count>0 Then
response.write &quot;Database Errors Occured&quot; & &quot;<br>&quot;
response.write SQLString & &quot;<br>&quot;
For each error in DBConn.Errors
response.write(Error.Number & &quot; : &quot; & Error.Description) & &quot;<p>&quot;
Next
End If

' Close Database
DBConn.Close
Set DBConn = Nothing

' Redirect User Depending on Search Outcome
If UserFound=&quot;False&quot; Then
response.redirect &quot;survy_grp.htm&quot;
Else
response.redirect &quot;restricted.htm&quot;
End If

' Check for VBScript Errors
If err.number>0 Then
response.write &quot;VBScript Errors Occured:&quot; & &quot;<br>&quot;
response.write &quot;Error Number = &quot; & err.number & &quot;<br>&quot;
response.write &quot;Error Descr. = &quot; & err.description & &quot;<br>&quot;
response.write &quot;Help Context = &quot; & err.helpcontext & &quot;<br>&quot;
response.write &quot;Help File = &quot; & err.helpfile & &quot;<br>&quot;
response.write &quot;Source = &quot; & err.source & &quot;<p>&quot;
End If
%>
 
What do you mean by &quot;everything works except...&quot; Are you not redirecting at all? For starters get rid of the &quot;On Error Resume Next&quot;. Then do a response.write of the value of &quot;UserFound&quot; directly before the redirect is supposed to happen. Make sure to put response.end right after that so the script doesn't continue.
 
Correct. I just get a blank page. However, I just removed the &quot;On Error Resume Next&quot; statement and now I recieve the following error:

Response object error 'ASP 0156 : 80004005'
Header Error
/~floridasurveys/index.asp, line 51
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.

Line 51 is the response.redirect statement on the TRUE side of the UserFound If statement. I've already tested the UserFound values and it works correctly.

Thanks
 
Add to the top of your page (1st line)
<%response.buffer=&quot;true&quot;%>
 
Sorry...not 1st line, enter it after your language declaration.
 
With your help I figured it out. For some reason the comment tag <!-- Make Data Connection --> was apparently causing the server to send output to the browser and therefore, caused a conflict. The &quot;On Error Resume Next&quot; statement was also hiding the error. Now that I removed the comment tag, everything works as it should.

Thanks for your help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top