473,545 Members | 2,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing ASP Session from ASP.NET via Session cookie

I have a site that I'm trying to migrate to ASP.NET from ASP, and the
foremost stumbling block I'm hitting is session state between the ASP
and ASP.NET applications. In order to access this information, I'm
doing a HttpWebRequest from the ASP.NET side into an .asp page,
passing the session name on the get in order to request it from the
ASP side and write it back to the response stream, giving ASP.NET
access to it. Of course I change sessions each time I make the call
from the ASP.NET side.

Soooooo, I'm thinking to myself, "Self, shouldn't you be able to fake
out the server by getting the session cookie from the initial usage of
the asp, pass that data to the ASP.NET, and use that to send a request
back the ASP side under the appropriate session?"

From a real high level, I enter the site via a .asp page. This page
in turn calls .aspx page from within a frame

<frame src="init.aspx? SessionCookie=< %=request.serve rvariables("HTT P_COOKIE")%>">

init.aspx calls a class that makes the call to the session lookup page
(called lookup.asp). The gist is as follows (rough draft):

string sReqURI = . . . defined to pass along the request on the get

HttpWebRequest oRequest = (HttpWebRequest )WebRequest.Cre ate(sReqURI);
oRequest.Cookie Container = new CookieContainer ();
System.Net.Cook ie oCookie = new System.Net.Cook ie(m_sSessionKe y,
m_sSessionValue );
oCookie.Domain = m_sDomain;
oRequest.Cookie Container.Add(o Cookie);

HttpWebResponse oResponse = (HttpWebRespons e) oRequest.GetRes ponse();

Stream receiveStream = oResponse.GetRe sponseStream();

System.Text.Enc oding encode =
System.Text.Enc oding.GetEncodi ng("utf-8");

StreamReader readStream = new StreamReader( receiveStream, encode );

char[] read = new char[256];
// Reads 256 characters at a time.
int count = readStream.Read ( read, 0, 256 );

while (count > 0)
// Dumps the 256 characters on a string and displays the string to the
sValue = new String(read, 0, count);
count = readStream.Read (read, 0, 256);
// Releases the resources of the response.
oResponse.Close ();
// Releases the resources of the Stream.
readStream.Clos e();

I can get a response, and if I set actual text in the asp page, I can
retrieve it, so I know that's fine. Can't access the previous
session, though. Anybody have any experience along these lines?

Jul 19 '05 #1
1 5779
Thanks for the reply. Actually, what I was trying to achieve was
passing the session cookie to asp.net and storing it there. Later, I
would make a call, from asp.net back to the asp page, spoofing out the
session cookie being sent in the asp request in the header, thus
getting back to the original asp session. Does this make my request


"Aaron Bertrand - MVP" <aa***@TRASHasp faq.com> wrote in message news:<uR******* *******@TK2MSFT NGP09.phx.gbl>. ..
I have a site that I'm trying to migrate to ASP.NET from ASP, and the
foremost stumbling block I'm hitting is session state between the ASP
and ASP.NET applications.

There is no such thing; they have completely independent sessions. You
cannot match a session cookie between an ASP session and an ASP.NET session,
because they have different SessionIDs (which is the identifier used to
locate the cookie for the user). You might have to pass around an
identifier of some sort on the querystring, to avoid this issue... maybe
avoiding sessions altogether, and persisting "session" data in a database or
something like that...

Jul 19 '05 #2

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

Similar topics

by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the...
by: ndsoumah | last post by:
hello guys I'm trying to get access to variables I put in a session variable from another page and it fails... here's the exact situation main file page1.php
by: William | last post by:
Hi I have an ASP.NET application that connects to an Access database. Everything works fine except for the Session object. Data in the session object is lost after I've made a call to the database. To test, I've created two test aspx pages. Test1.aspx contains two buttons. The first button sets values in the session object and then...
by: Ravi Ambros Wallau | last post by:
Guys: Is there someway that allows a normal (and old) ASP page to access Session _or_ Application data of an ASP.NET page? I can't migrate this ASP page to ASP.NET. This ASP page loads an ISAPI filter (msmdpump.dll), and I've tried a lot, but can't make this works in ASP.NET. Thanks, Ravi.
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or updating the code-behind dll) accessing any aspx page in the application causes the application to run for the first time. Some of the initialization...
by: Dave Alvarado | last post by:
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...
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when user close the browser window then open a new browser, FormsAuthentication reads from cookie and user logs in. Althought user logged in, session...
by: Justin Engelman | last post by:
Hi, I have a website that uses an ISAPI filter that will redirect anyone going to any page on the site to an SSL login page (on a different website with the same root domain) if they do not have the appropriate session cookie already. After logging in on that page successfully they are given the cookie and redirected back to the page they...
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the session and then I use the following code to try and get a stream of image data. mypage.aspx has a different session ID then the calling page. I tried...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.