Possible to 'recapture' a asp.net session?

M

Marcus

I have an ASP.Net 2.0 app that needs to jump out onto another web
server running a java server page website (Apache TomCat 4.1.12) that
I control. I hate that it needs to do this, but we are using some
internet GIS mapping web tool that comes "precanned" with lots of
mapping ability and its pages run on JSP. Theasp.net Session_End event
is quite important to catch as there is a lot of cleanup that needs to
happen in the database relating to the user of that session. Thus, I
need to maintain the session across ASP.Net and JSP webservers. A
hackish way that I accomplished this was to use cookieless sessions
which embeds the session id in the url (e.g.
http://www.abc.com/(S(2zmfutqdfdvm2amvmjpljovi))/Introduction.aspx),
have the jsp side parse out the session id and keep it around while
the user does what they need to do on the jsp pages, and then when it
is time to return to the ASP.Net side just construct a url that has
the cookieless session format with the same session id.

This works OK, but cookieless sessions have some limitations (e.g.
must use only relative addressing). Is there any other way that I can
recapture a session when I return to an asp.net page where I formerly
had a session just moments before? This is all required because I need
to capture that session_end event. It would be great if I could just
pass around a sessionid in the query string and create a session with
that specified id, but that doesn't appear to be possible.

Thanks.
 
K

Kevin Spencer

You don't need to maintain the Session to ensure that the Session_End event
fires. The Session_End Event will fire as soon as the Session times out on
the server. It is a server-side event that happens without any interaction
with the client. The only part that the client has in terms of Session_End
is keeping the Session alive. The Session is on a timer, and when the timer
elapses, the Session_End event fires. When a Request from the same client
comes back, the timer is reset.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

This works OK, but cookieless sessions have some limitations (e.g.
must use only relative addressing). Is there any other way that I can
recapture a session when I return to an asp.net page where I formerly
had a session just moments before? This is all required because I need

hmm. but what about "normal" cookie-based session?
 
M

Marcus

Well, the thing is, when I leave the asp.net page and head over to
jsp, I loose the asp.net session. When I come back to the asp.net
page, I want to reestablish that same session so that the session_end
event will be raised only after this reestablished session has timed
out, not after a certain timeout period from when I first left the
asp.net page. There is a lot of user data in the database that both
the asp and jsp sides are accessing. When the session expires, I want
to remove this data. I have the cleanup code in the session_end event,
but if I can't reestablish the session, then the user data will be
removed prematurely.

One approach I might try is to record in the database the last access
time for a particular user for the site (thus for each page load this
would be updated). Then I could create a job in Sql Server that runs
every few minutes that does the data cleanup for the user once a
particular amount of time has passed from the last page access to the
current time.

M.
 
M

Marcus

I would prefer cookie based sessions, but still how do I re-establish
the session once I return to the asp.net page? It would be great if I
could assign the old session id (which would likely still be active)
to the new session object, but I don't think that is possible.

M.
 
G

Guest

I would prefer cookie based sessions, but still how do I re-establish
the session once I return to the asp.net page? It would be great if I
could assign the old session id (which would likely still be active)
to the new session object, but I don't think that is possible.

A session will expire when the time specified by the timeout passes
without a request being made for the session. And you can go to
another server and go back and get the session back during the time of
timeout. If you don't know what timeout you will need and to ensure
availability, a session can be extended by request (e.g. by a time
based javascript).

As I understand, the main problem is in the cache of user data in the
database. You shouldn't use the Session_End event to clean it up
(because it does not always fire), you need to make a job in Sql
Server. But here, I guess, will a problem that you don't know if you
can delete the cache or not...

Another approach can be a SQL Server mode session, that stores a
session in a SQL Server database. In this case, I think you can find
the time when the session has been updated.
 
K

Kevin Spencer

That's an idea. A database is about the only thing you can count on. You can
store a unique identifier in the user's Cookies, which can be used to hook
the user back up to their cached data.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top