There are at least three valid answers to this, depending on your goal.
- If you need to make sure that someone has been to a.asp before you will process anything on b.asp, you can set a session variable in a.asp that flags a.asp as having been visited. Check for this session variable in b.asp; if it exists/is true, do the processing.
a.asp:
<% session("VisitedPageA") = true %> |
b.asp:
<% if (session("VisitedPageA")) then Response.Write "They've been to page a." else Response.Redirect "a.asp" end if %> |
- If you need to make sure that b.asp is only accessed once per session, you can set a session variable in that page, check to see if that variable exists... if it does, that means they've already been there.
a.asp:
<% if (session("VisitedPageA")) then Response.Write "Hey, you've already been here!" Response.End else session("VisitedPageA") = true end if %> |
Remember that not all users have enabled session cookies, so for some users, the above solutions won't work.
- If you need to make sure that someone goes directly from a.asp to b.asp, check Request.ServerVariables("HTTP_REFERER") in b.asp. If it's not a.asp, then they didn't arrive here through the proper route.
a.asp:
<% Response.Redirect "a.asp" %> |
b.asp:
<% ref = Request.ServerVariables("HTTP_REFERER") if lcase(ref) <> "http://yourserver/yourpage.asp" then Response.Redirect "a.asp" end if %> |
However, you might need a workaround, depending on how users move around your site (see Article #2169 for information about the problems with HTTP_REFERER).