Redirect if passed parameter has been amended by a user to something not in database.

J

jon

Hi,

I've created a page, that looks up a URL form my database depending on a
value "LINK_ID" thats passed in the url.

If the user amends the LINK_ID=1 in the url to LINK_ID=9999 ( or any other
ID that isnt in my database) then I want to redirect them to a different
page. (Im using a hosted package and I cant edit the error pages).

Heres my ASP, can anyone show me how to do this ?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If
%>
<%
Dim Get_Destination
Dim Get_Destination_numRows

Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()

Get_Destination_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<% Response.Redirect ((Get_Destination.Fields.Item("Link_path").Value)) %>

</body>
</html>
<%
Get_Destination.Close()
Set Get_Destination = Nothing
%>


Thanks

Jon
 
B

Bob Barrows

jon said:
Hi,

I've created a page, that looks up a URL form my database depending
on a value "LINK_ID" thats passed in the url.

If the user amends the LINK_ID=1 in the url to LINK_ID=9999 ( or any
other ID that isnt in my database) then I want to redirect them to a
different page. (Im using a hosted package and I cant edit the error
pages).

Heres my ASP, can anyone show me how to do this ?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Get_Destination.Open()

if Get_Destination.EOF then
Get_Destination.close
response.redirect ...
else
....
 
J

jon

Thanks for the quick response Bob,
I amended my code to this but it still doesnt work, can you see whats wrong
? , I also tried putting the www.google.com in quote marks but still no
luck.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If
%>
<%
Dim Get_Destination
Dim Get_Destination_numRows

Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()

if Get_Destination.EOF then
Get_Destination.close
Response.Redirect (http://www.google.com)
else

Get_Destination_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<% Response.Redirect ((Get_Destination.Fields.Item("Link_path").Value)) %>

</body>
</html>
<%
Get_Destination.Close()
Set Get_Destination = Nothing
%>
 
D

Daniel Crichton

You're missing an End If before Get_Destination.Close() near the bottom of
the code.

Dan

jon wrote on Thu, 18 Dec 2008 15:01:29 -0000:
Thanks for the quick response Bob,
I amended my code to this but it still doesnt work, can you see whats
wrong ? , I also tried putting the www.google.com in quote marks but
still no luck.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If %>
<%
Dim Get_Destination
Dim Get_Destination_numRows
Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()
if Get_Destination.EOF then
Get_Destination.close
Response.Redirect (http://www.google.com)
else
 
D

Daniel Crichton

If you still get an error, it'll be due to having .Close() twice (once when
you do the redirect, and again at the end of the code) - you can remove the
one above the Redirect call, or move the End If I suggested to below the
second call to Close(), or add a Response.End under the Redirect line.

Dan

jon wrote on Thu, 18 Dec 2008 15:01:29 -0000:
Thanks for the quick response Bob,
I amended my code to this but it still doesnt work, can you see whats
wrong ? , I also tried putting the www.google.com in quote marks but
still no luck.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If %>
<%
Dim Get_Destination
Dim Get_Destination_numRows
Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()
if Get_Destination.EOF then
Get_Destination.close
Response.Redirect (http://www.google.com)
else
 
B

Bob Barrows

No, I will not be able to see what is wrong. You will need to add some
Response.Writes to your code to enable you to see the value of the
variables and see what is going on.

Specifically:

Response.Write Get_Destination__MMColParam & "<BR>"

and

Response.Write Get_Destination.Source & "<BR>"
 
J

jon

Hi Dan,
Thanks for your help.

None of these worked, but removing the else and replacing it with an end if
did.

Here is my final working code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If
%>
<%
Dim Get_Destination
Dim Get_Destination_numRows

Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()

if Get_Destination.EOF then
Response.Redirect ("http://www.google.com")
End if

Get_Destination_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<% Response.Redirect ((Get_Destination.Fields.Item("Link_path").Value)) %>

</body>
</html>
<%
Get_Destination.Close()
Set Get_Destination = Nothing
%>

Again, Thank you for your help, I hope you all have a very nice christmas.

Jon
 
N

Neil Gould

jon said:
Hi Dan,
Thanks for your help.

None of these worked, but removing the else and replacing it with an
end if did.

Here is my final working code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/DataLinks.asp" -->
<%
Dim Get_Destination__MMColParam
Get_Destination__MMColParam = "1"
If (Request.QueryString("Link_ID") <> "") Then
Get_Destination__MMColParam = Request.QueryString("Link_ID")
End If
%>
<%
Dim Get_Destination
Dim Get_Destination_numRows

Set Get_Destination = Server.CreateObject("ADODB.Recordset")
Get_Destination.ActiveConnection = MM_DataLinks_STRING
Get_Destination.Source = "SELECT * FROM TBL_LINKS WHERE Link_No = " +
Replace(Get_Destination__MMColParam, "'", "''") + ""
Get_Destination.CursorType = 0
Get_Destination.CursorLocation = 2
Get_Destination.LockType = 1
Get_Destination.Open()

if Get_Destination.EOF then
Response.Redirect ("http://www.google.com")
End if

***********************
Get_Destination_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" /> <title>Untitled Document</title>
</head>

<body>

<% Response.Redirect
((Get_Destination.Fields.Item("Link_path").Value)) %>

</body>
</html>
<%
Get_Destination.Close()
Set Get_Destination = Nothing
%>
*************************
It appears that you are relying on the redirection to clear the error that
would be generated if "Get_Destination.Fields.Item("Link_path").Value"
doesn't exist. The idea of the "else... end if" portion is to run this code
only if the link_path condition is valid, so if you are getting an error
with the else clause in place, it's likely due to some other factor that, as
Bob has pointed out, may be traced with some response.writes to isolate the
source. I'd recommend that you chase this one down.

Best,

Neil
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top