I created a page in ASP that loads dynamic content with code similar to this:
<%
var1 = int(rnd * 5) + 1
var2 = int(rnd * 10) + 1
%>
<html>
<body>
what variable 1 is: <%=var1%>
what variable 2 is: <%=var2%>
</body>
</html>
Then I have another page that uses Server.Execute to execute the previous file mentioned 2+ times using a loop. The code looks like this:
<% filename = request.querystring("page") %>
<table class="domtable">
<% for j = 1 to 2%> <%qnumb = qnumb + 1%>
<tr>
<td align="left">
<%server.execute (filename)%>
<% If qnumb < 2 then%>
<br/><hr><br/>
<%end if%>
</td></tr>
<%next%>
</table>
So for the last couple of months this has been working perfectly for me, loading different numbers for both variables on the two separate executions. Then today, I duplicated a folder on my server, renamed it and now magically, the variables are the same number about 9 out of 10 times the browser is refreshed.
This happened to me with the same files on my second server a month ago, and I had to delete all the files off of the second server, and download them from my first server (the one duplicating now), then upload them back and that fixed it. Unfortunately, I didn’t download the entire server contents of my first server so I’m unable to reverse the process. So I’m not sure if this issue is server-side, or if it’s related with the code I’m writing? I just don’t know why it would work for so long then just stop working out of nowhere.
I’ve tried using meta no-cache controls. I deleted the new folder I duplicated earlier from the server and that didn’t work. I also tried deleting files from the last couple days that have been uploaded and that didn’t work either. I’ve tried loading ‘filename’ as an array such as:
filename(1) = request.querystring("page")
filename(2) = request.querystring("page")
for j = 1 to 2
Server.Execute(filename(j))
next
I really hope someone knows what I’m doing wrong here.
-EDIT-
I’m also doing this and getting the same results.
<%
'rnd.asp'
pStr = "private, no-cache, must-revalidate"
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", pStr
server.execute ("rndj.asp")
response.write ("<hr>")
randomize(3)
server.execute ("rndj.asp")
%>
<%
'rndj.asp'
pStr = "private, no-cache, must-revalidate"
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", pStr
randomize
response.write rnd
response.write "<br>"
response.write rnd
%>
I started to use this code below which looks at the specified file as plain text and removes the asp tags from it then uses Execute to run it within the original file. The problem with this is all my pages that i call use in them for other resources and the replace script wont let me add asp tags around the include lines.
<%
Dim sTargetFile, sTargetFileContents
Dim oFSO, sContents
Function GetFileContentsForExecution(sTargetFile)
'Obtain a reference to the FileSystemObject
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
'Obtain the file contents
sContents = oFSO.OpenTextFile(Server.MapPath(".") & "\" & sTargetFile).ReadAll
Set oFSO = Nothing 'reference to the FileSystemObject
'Remove the ASP scripting tags
rand = int(rnd * 2)
sContents = Replace (sContents, "<" & "%", "")
sContents = Replace (sContents, "%" & ">", "")
GetFileContentsForExecution = sContents
End Function
sTargetFile = "rndj.asp"
for j = 1 to 6
'Get the contents of the file to execute
sTargetFileContents = GetFileContentsForExecution(sTargetFile)
Execute sTargetFileContents
next
if j < 3 then
response.write ("<br/><hr><br/>")
end if
%>
Link to working solution
%>