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

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
%>
 
o.k this is actually an ASP forum question, but i will answer it. cannot use a response.redirect after outputting anything to a browser. a simple example ought to explain it:
this wont work:
<%
response.write &quot;ASD&quot;
response.redirect &quot;ASPPage&quot;
%>
neither will this:
<html>
<%
response.redirect &quot;ASPPage&quot;
%>


but this will work:
<%
response.redirect &quot;ASD&quot;
%>


that is because in the first case ASD has been outputted to the browser. and in the second case it is not response.write but still the tag <html> is outputted to the browser...

hope i am clear...

Known is handfull, Unknown is worldfull
 
Try

If UserFound=&quot;False&quot; Then
response.redirect(&quot;survy_grp.htm&quot;)
Else
response.redirect(&quot;restricted.htm&quot;)
End If
 
that not the problem cheerio. the brackets are optional...

Known is handfull, Unknown is worldfull
 
Both previous postings made at the same time - go with vbkris
 
I totally overlooked the ASP forum. My bad. However, my response.write statements will never be accessed unless there’s an error. But in any case, I went ahead and commented out my write statements and still got the same results, a blank screen. Unless I’m overlooking something, nothing is being sent to the browser other than the redirected URL which for some reason isn’t working.

Thanks
 
I posted to the ASP forum and someone helped me figure 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!!!
 
aha like i said so...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top