469,303 Members | 1,980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,303 developers. It's quick & easy.

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.servervari ables("HTTP_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.Create(sReqURI);
oRequest.CookieContainer = new CookieContainer();
System.Net.Cookie oCookie = new System.Net.Cookie(m_sSessionKey,
m_sSessionValue);
oCookie.Domain = m_sDomain;
oRequest.CookieContainer.Add(oCookie);

HttpWebResponse oResponse = (HttpWebResponse) oRequest.GetResponse();

Stream receiveStream = oResponse.GetResponseStream();

System.Text.Encoding encode =
System.Text.Encoding.GetEncoding("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
console.
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.Close();

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?

Thanks,
Dax
Jul 19 '05 #1
1 5571
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
clearer?

Thanks,
Dax

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message news:<uR**************@TK2MSFTNGP09.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by mrbog | last post: by
8 posts views Thread by ndsoumah | last post: by
3 posts views Thread by William | last post: by
6 posts views Thread by Ravi Ambros Wallau | last post: by
5 posts views Thread by Şenol Akbulak | last post: by
5 posts views Thread by gom | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.