Read ASP.Net Cookie from Classic ASP - asp.net

I'm having some trouble reading the ASP.NET cookie from a Classic ASP file. Here is the code i'm using:
First off, I have the ASP.NET site setup in IIS. I setup an Application in the ASP.NET site and directed it to another folder in inetpub. This Application is called '/classicasp' because its all classic asp inside that application.
In the .aspx file, it is executing this code:
Response.Cookies["testcookie"].Path = "/classicasp";
Response.Cookies["testcookie"].Value = "test";
In the .asp file, it is executing this code:
<%
for each cookie in Request.Cookies
Response.Write( cookie & "=" & Request.Cookies(cookie) & "Path:" &
"<br>")
next
%>
But the .asp page is empty, there are no results displayed on the page from this For Next statement.. Any help on why this is happening? I think i followed instructions and am doing this how its supposed to be, but i guess not..

try
dim x,y
for each x in Request.Cookies
response.write("<p>")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
response.write("<br />")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "<br />")
end if
response.write "</p>"
next

I think this is what you are looking for:
Updating ASP cookie from ASP.NET (vice versa)

Related

how to get current line number in Classic ASP code

I'm trying to find a way how to get the code line number in Classic ASP
<%
Response.Write "Hello world!<br>"
Response.Write getThisLineNumber() & "<br>"
Response.Write "Goodbye world."
%>
Expected output
Hello world.
3
Goodbye world.
getThisLineNumber() is a fictional function doing what I'm looking for.
I temporarily solved my problem by
<%
Response.Write "Hello world!<br>"
Response.Write "3<br>"
Response.Write "Goodbye world."
%>
but when i add a new line after "Hello world." (2nd line), then I manually must change
Response.Write "3<br>"
to
Response.Write "4<br>"
Classic ASP does not support such a feature, it's something like Reflection in .NET.
The closer thing you can do is get line number when an error happens in Err object, this way: Err.Line.
If you want to profile an asp page, maybe ASP Profiler can help you: ASP Profiler

Lost ASP Session Variable IIS 6.0 to 7.5

I've read a lot about the topic, but I don't get the solution.
I've tried all the solutions the community has posted, but not success.
I am migrating a site from IIS 6.0 to 7.5. The site has both ASP and ASP.NET applications, so I set two different pools.
The ASP.NET apps work without problems.
Where I have the problems is with the ASP applications. All the ASP apps use another app whose objective is to grant the user. The problem becomes when the granting-user app creates a session ("accepted") variable and it gets lost when redirecting. This feature was working in IIS 6.0
I've traced the problem and confirmed that the error comes when redirecting.
What I've tried and checked to fix the problem:
Session Properties
Enable Session State = true
Time-out: 00:20:00
Mode Settings: In Process
Cookie Settings = Use Cookies
Use hosting identity form impersonation = checked
Port to access the site: :8685
I've also checked the web-gardening and it's not enabled as there's only 1 working process set.
I attach the screen captures I consider relevant
I've coded an ASP page which shows the session variable contents. Before redirecting, the session variable is correctly created, but when the redirection takes place, the information is lost.
I attach the code my enterprise policy let me to post:
response.write("Accepted: " & session("aceptado") & "<br>")
response.write ("SQL: " & mySQL & "<br>")
response.write("Accepted: " & session("aceptado") & "<br>")
dim i,j
j = Session.Contents.Count
Response.Write("Session contents: " & j & "<br>")
Response.Write("Contents: <br>" )
For Each i in Session.Contents
Response.Write(i & "<br>")
Next
Response.write("isNull: " & IsNull(Session) & "<br>")
Response.write("¿Aceptado? " & Session("aceptado"))
With the above code, the result is:
The code to check the session status once the redirect takes place is:
<%response.buffer = true
%>
<html>
<h1>test</h1>
<%
dim i,j
j = Session.Contents.Count
Response.Write("Session contents: " & j & "<br>")
Response.Write("Contents: <br>" )
For Each i in Session.Contents
Response.Write(i & "<br>")
Next
%>
isNull: <%=IsNull(Session)%> <br>
¿Aceptado?: <%=Session("aceptado")%><br>
incidencia : <%=Session("tipoincidencia")%><br>
usuario : <%=Session("usuario")%>
</html>
The result executing the above code:
The redirection takes place between the last two images
My Workaround for this is to simply start a ajax call every X (where X is roughly half the time in wich the session expires, in my case 7.5min ).
It's not super clean, but gets the job done.

VBScript FileExists fails consistantly

We're trying to read some log files for our application but FileExists is failing in every case. So I simplified the problem with this test code:
Dim filespec, msg
filespec = Chr(34) & "C:\Windows\explorer.exe" & Chr(34)
'filespec = "C:\Windows\explorer.exe"
'filespec = Chr(34) & "C:" & Chr(34)
'filespec = "C:"
'filespec = "default.asp"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
As you can see, we've tried testing with and without added Chr(32) (which is the double quote character). We're testing against the file C:\Windows\explorer.exe and the file C:\Windows\explorer.exe does exist on the computer hosting the asp files and the iis server. We even fail when simply checking to see if the C drive exist.
Additionally, it even fails if we try to see if the default.asp file exists and that file is in the same directory as our filetest.asp file.
Does anyone see why our FileExists is consistently failing? Thank you.
filespec = "C:\Windows\explorer.exe"
Without the additional quotes will work. To find a folder we need to use
fso.FolderExists
Instead of FileExists.
This still doesn't find the default.asp file in the same directory. But that problem is too far removed from our actual problem which is to look at log files on another drive. That problem is too far from this original question so I'll post that problem separately.
You may want to try to load the folder in to a folder object and loop through files in the folder object. Below is an example.
Set fso = CreateObject("Scripting.FileSystemObject")
FileToFind = "explorer.exe"
FolderToSearch = "C:\Windows\"
Set myFolder = fso.GetFolder(FolderToSearch)
For each myFile in myFolder.Files
If myFile.Name = FileToFind Then
Wscript.echo "Found " & myFolder.Path & "\" & myFile.Name
End If
Next
you do not need to insert additional quotes. removing your quotes will work just fine.
Dim filespec, msg
filespec = "C:\Windows\explorer.exe"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
In the past, I have only noticed that you need to insert additional quotes when using the wshshell.run since a space might be interpreted as additional arguments to the filename.
It appears that our problem is not in the VBScript at all. The app is running inside an ApplicationPool in iis. The Identity property of that Application Pool is the dynamically created applicationPoolIdentity user. This is a user with no permissions. So essentially, the application is running as a user which does not have access to any other drives. Therefore, it cannot find any file on any network drive. We will have to create an additional identity with the proper rights and set our applicationPool identity to use that custom account.
I found instructions on how to set this identity account here: http://technet.microsoft.com/en-us/library/cc771170%28v=ws.10%29.aspx

Application level variable initialization in asp classic

I have legacy ASP classic website. If I dump all the application variables using
For Each item In Application.Contents
Response.Write item & " = " & Application(item)
Response.Write "<br>"
Next
They are all initialized but there is no global.asa file in this application.
Where else the initialization code might be?
just add this code in any .asp file and add this file as a top usercontrol in every page so you will get this variable on all pages
session is the other option , you can assign all variable in session and can access in any page (I do not recommend this.)

Asp pattern page execution

I am working on an old asp project. I am new in project. My question is,
I required to execute the certain number of pages in a specific time but when I put in a loop to execute the page for certain pattern it execute only one pattern and shows time out expired problem. Though I searched in net what ever answer I get it will not fulfill my requirement. So my team lead said we have to find out some thing that can execute my page for 3 min each then it call back freshly. Is there any method is there in asp. as I am new in asp. as it possible or share some idea.
I want to execute for each pattern. Here is my simple code.
dim arrList()
dim mySQL,x,strPtrn
mySQL=""
x=0
strPtrn=""
mySQL="select distinct(pattern_no) from pattern_master where std between (dateadd(hh,8,getdate())) and (dateadd(hh,11,getdate()))"
set rstptrnmst= conn.Execute(mySQL)
do until rstptrnmst.EOF
for each ptrn in rstptrnmst.Fields
' Response.Write(x.name)
'Response.Write(" = ")
'Response.Write(x.value & "<br />")
ReDim Preserve arrList(x)
arrList(x)=ptrn.value
x=x+1
next
Response.Write("<br />")
rstptrnmst.MoveNext
loop
rstptrnmst.close
conn.close
'for each ptrn in arrList
'response.Write("<br>" & ptrn)
'next
for each ptrn in arrList
Session("pattern")=ptrn
server.Execute("processFNO.asp")
Session("pattern")=""
response.write("The first pattern " & ptrn & "<br />")
next
'Response.Redirect("processFNO.asp?fno="&arrList(0))
%>
So I want execute that page for each pattern. How can I? For each pattern it take 3 min(approx).any idea?
thanks for advance.
If your script is going to take that long to run you will need to set the script timeout option to cater for that:
<%
Server.ScriptTimeout = 180
%>
The timeout is set in seconds, with the default being 90. You should set this at the very top of your page.
More information about timeouts here: How do I increase timeout values

Resources