473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
Nov 19 '05 #1
0 1394

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David | last post by:
Hi, I write asp.net via c#. How should I know the client's session alive? 1. if ( Session.Equals ( null ) ) 2. if ( Convert.IsDBNull(Session) ) 3. if ( Session.Contents.Count == 0 ) Thanks...
2
by: Showjumper | last post by:
Is there a peformance hit when using inline code? As an example, lets i store a user's preferences for backgtound color of a page. When he/she logs in, i stick the color value into their session...
1
by: twscott | last post by:
I will be posting information to another application from my applicatio and redirecting to that application which will load into anothe iteration of IE. The user may spend a significant amount of...
0
by: le0 | last post by:
hi guys can you help me with this, this is my first time to published a website to another server and access it using my browser but this runtime error always appears. Server Error in...
0
by: Ramchandar | last post by:
In my aspx page i want the lot of informations to be filled by the user. But wen the user takes some break to fill the form n resumes after some time the page gets expired. So to keep the session...
1
by: soni2926 | last post by:
hi, i'm working on a site, which has a session created after a user logins, each page checks to make sure the session is there onload otherwise redirects to the login page. now the clients are...
2
by: tokcy | last post by:
Hi All, I want to kip session alive until i closed the browser. Default session time 30 minutes and if we are using session.gc_maxlifetime then i have to give specific time like 8 hrs or...
1
by: Larsr | last post by:
Hi, in building a navigation system, I would like to use a system where I have, say, four links which naturally are different pages. Initially, all links are, say, blue. When clicking on the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.