Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: ASP.NET FAQ

Session State

How can I use classic ASP Session w/ ASP.NET? by link9
Posted: 27 Dec 02

Hello all --

I recently stumbled across this article on http://www.eggheadcafe.com and thought it was brilliantly simple and effective.  I've cut the relevant part of the code out of the article to post here verbatim, and provided a link to the full article (lest the site go bye-bye, we still get to keep the "good stuff").

Basically, reading directly from asp classic session is not possible through asp.net, but a simple workaround is to pull all session from asp classic, graft it onto a form, submit that form to an asp.net page, and stuff it into asp.net session.  Very simple and easy to do.

So, without further ado:

' This is the page where we just set some Classic ASP Session Variables
' ASPPage2.asp is where the work is done.

' We graf all the session variable names/values and stick them in a form
' and then we submit the form to our receiving ASP.NET page (ASPNETPage1.aspx)...
Response.Write("<form name=t id=t action=ASPNETPage1.aspx method=post >")
For each Item in Session.Contents
Response.Write("<input type=hidden name=" & Item)
Response.Write( " value=" & Session.Contents(item) & " >")

<%@ Page language="c#" %>
<script runat=server>
// We iterate through the Form collection and assign the names and values
// to ASP.NET session variables! We have another Session Variable, "DestPage"
// that tells us where to go after taking care of our business...
private void Page_Load(object sender, System.EventArgs e)
for(int i=0;i<Request.Form.Count;i++)

<%@ Page language="c#" %>
<script runat=server>
// This page is just a "proof of concept page"...

private void Page_Load(object sender, System.EventArgs e)
Response.Write("Shared Session Variable Names/Values between Classic ASP and ASP.NET:<BR>");
for (int i = 0; i < Session.Contents.Count; i++)
Response.Write("Assigned to \"" +Session.Keys[i].ToString()+"\"");
Response.Write(" Value: "+ Session[i].ToString() +"<BR>");

And the link to the full article (hope it's not broken):

So thanks to the guys at eggheadcafe.  And remember:  K.I.S.S.!

Happy Coding!
Paul Prewett

Back to Microsoft: ASP.NET FAQ Index
Back to Microsoft: ASP.NET Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close