ASP: Sustain Remote Cookie Sessions in an ASP/VBScript

I dug up this cold from my old netnerds blog. For Googlers wondering if sustaining a remote session is possible, the answer is yes; I’ve sustained remote cookie sessions using both ASP & VBScript. I’ve provided simplified code below. It should be self explanatory. If not, drop me a comment and I’ll explain it.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

I had a similar need and a similar problem hence me finding this page. I think I’ve found out why it won’t work but it might not help you. Its seems that only one page can have access to a users session space at one time but you (or we) are trying to access it in both pages. As a result the second page hangs while it waits for the firstpage to finish processing and release the session but it can’t as the first page is waiting for the second to finish running…dead lock. Thats whats causing this method to not work. The only way around it I’ve found is to switch off sessions in the first page, the calling page then the second page has access to the session space. Not perfect but it might serve your needs it did mine. You can switch it off by add this line to the top of your page:

Hi Chrissie – I am trying to get this to work with session variables as
well as cookies so I’ve got
xmlhttp.setRequestHeader “Cookie”, “LOGGED=xxxxxxxxxx”
xmlhttp.setRequestHeader “Cookie”, “MYID=xxxxxxx”

works fine – however how do I get this to run with session variables
is it just a case os writing
xmlhttp.setRequestHeader “Session”, “MYSession=xxxxxxx”

For anyone interested, I wrapped Chrissy’s method around a slightly different friendly API for VBScript, and for Javascript as well. It might not be perfect but it’s a start. The Javascript version is intended to be cross-platform.

hi Chrissy,
your script is very useful. I wish to use it to send my vote in a web poll. In order to do that, I need to simulate send data via form.
I know the URL to the page to vote, but I dont know the URL to the module which stores the vote (in the HTML I got ).
Is there a way to retrieve the destination URL? Can I send form data using a cookie?
thanks

hi, i need help about xmlhttp connection a site..
page have login and password textfield.. but this form elements name are generated Random by server
for examle when you enter page :
name=”6100cf004601fc245d21aa880fde8ce3″ id=”tagLogin” type=”text”
type=”password” maxlength=”10″ name=”83006400c2011c24d821c688ecdf1816″

if you enter page and delete cookie.. page say you must enter all variables in form.
if you dont delete cookie.. page login successfully..

i connect the page with : Msxml2.ServerXMLHTTP.3.0
and send User-Agent Google Chrome
and first connection i get the cookie value with that:

This is the second time on this project a Google search brought me to a posting from you that is exactly what is needed. Thank you for posting things of this nature. They are a big help to those of us getting into areas we have not trod before. Haven’t tried it yet, but it looks perfect.

This is nice code. But you could have used Application(Request.ServerVariables("REMOTE_ADDR")&"YOURKEY") and save a delimited string. The user is redirected to the new site and parse the demimited string using Split add the cookies and use Application.Contents.Remove(Request.ServerVariables("REMOTE_ADDR")&"YOURKEY").