Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Keeping a session alive when accessing an ASP page with .Net code

Reply
Thread Tools

Keeping a session alive when accessing an ASP page with .Net code

 
 
=?Utf-8?B?RGF2ZSBBbHZhcmFkbw==?=
Guest
Posts: n/a
 
      09-01-2005
I'm working on some code that gathers data from a web interface to one of our
servers (classic ASP). The problem is that the site uses session variables
to store login information, so to move from page to page I need to emulate a
browser keeping a session active.

I'm currently using the .Net code below to access each web page. If I get
back an ASPSESSIONID cookie, I store it in a Cookie object, and keep passing
that object back every time I make a new request. However, it isn't working
properly--every request generates a new session on the web server. What am I
doing wrong?

Function GetHTTPRequestAsStream(ByVal strURI As String, ByRef SessionCookie
As Cookie) As Stream
Dim objURI As Uri
Dim objHTTPRequest As HttpWebRequest
Dim objHTTPResponse As HttpWebResponse
Dim objStream As Stream
Dim i As Integer

objURI = New Uri(strURI)

'Make the request
objHTTPRequest = HttpWebRequest.Create(objURI)
objHTTPRequest.UserAgent = "msie 6.0"
'If we have a session cookie, use it
If Not SessionCookie Is Nothing Then
objHTTPRequest.CookieContainer = New CookieContainer
objHTTPRequest.CookieContainer.Add(SessionCookie)
End If

objHTTPResponse = objHTTPRequest.GetResponse()

'If we didn't have a session cookie, grab the one that was returned
If SessionCookie Is Nothing Then

SessionCookie = New Cookie
For i = 0 To objHTTPResponse.Headers.Count - 1
If InStr(objHTTPResponse.Headers(i), "ASPSESSION") > 0 Then
SessionCookie.Name =
objHTTPResponse.Headers(i).Split(";")(0).Split("=" )(0)
SessionCookie.Value =
objHTTPResponse.Headers(i).Split(";")(0).Split("=" )(1)
SessionCookie.Domain = strURI
SessionCookie.Path =
objHTTPResponse.Headers(i).Split(";")(1).Split("=" )(1)
End If
Next

End If

objStream = objHTTPResponse.GetResponseStream
GetHTTPRequestAsStream = objStream

End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How keep python socket alive for ever by setting Keep alive flag. hisan Python 1 06-25-2012 05:30 PM
keeping session alive after browser closed, possible? soni2926@yahoo.com ASP .Net 1 09-19-2008 09:20 AM
What is the best way of keeping a server-side object alive between page refreshes? damian.jolly@sageautomation.com ASP .Net 2 05-03-2006 12:47 PM
Keeping session alive using jakarta httpclient Michael Fortin Java 1 10-12-2004 02:13 PM
Keeping a Session alive during long downloads hoenes1 ASP .Net 0 08-16-2004 12:02 PM



Advertisments