Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Access classic asp session variables from asp.net

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 18-05-2009
Member
 
Join Date: Apr 2009
Posts: 87
Access classic asp session variables from asp.net
  

I have .aspx pages in my ASP .net project. The problem is i want to access session variable in asp page which are created in .net page. Is that possible to access session variables from Classic ASP to ASP.NET.

Thanking you

Reply With Quote
  #2  
Old 18-05-2009
Member
 
Join Date: May 2008
Posts: 2,001
Re: Access classic asp session variables from asp.net

You can not use query and you can not pass the whole session if you want to pass a session variable.first store the session in your database and you can also configure this in your IIS for session variable.After that you can access database through asp like you access your database in normal way.
Reply With Quote
  #3  
Old 18-05-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: Access classic asp session variables from asp.net

You need to implement your own solution for accessing the variable of asp through ASP.net. You cannot use the ASP.NET and ASP sessions together by default .
Reply With Quote
  #4  
Old 18-05-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: Access classic asp session variables from asp.net

Code:
<TITLE>ASPPage1.asp</TITLE>
<%
' This is the page where we just set some Classic ASP Session Variables
' ASPPage2.asp is where the work is done.
Session("username")="joeblow"
session("email")="joe@blow.com"
Session("userid")=2
Session("DestPage")="Finalpage.aspx"
Server.Transfer("ASPPage2.asp")
%> 

==========================================================================

<TITLE>ASPPage2.asp</TITLE>
<%
' 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) & " >")
next
Response.Write("</FORM>")
Response.Write("<script>t.submit();</script>")
%>

============================================================================
<TITLE>ASPNETPage1.aspx</TITLE>
<%@ 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++)
{
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();
}
Server.Transfer(Session["DestPage"].ToString(),true);
}
</script>
==============================================================================

<TITLE>FinalPage.aspx</TITLE>
<%@ 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>");
} 
}
</script>

As can be easily seen, all we need to do is grab the Classic ASP Session variables, contruct a dynamic form in a new Classic ASP page consisting of their names and values as hidden form fields, and submit it to our receiving ASP.NET page where we simply iterate the Form NameValueCollection , sticking the names and values into ASP.NET variables! You want to use Server.Transfer because its much more efficient than making another browser trip with Response.Redirect.

To make it more extensible, one of the Session variables, "DestPage" is used to tell us "where to go" when we're done with our little conversion. You would probably want to set this in the page that makes the call to the utility page, ASPPage2.asp. In this manner, you can use the two pages ASPPage2.asp and ASPNETPage1.aspx in almost any situation. And don't forget - you can reverse the process just as easily to transfer ASP.NET Session variables back to Classic ASP! As a last note, one reader commented about how you would handle the fact that somebody was in the ASP.NET portion of your site and meanwhile their Classic ASP session had expired. No problem! Since you brought all your session "baggage" with you when you came over, all of it (including any new stuff) would simply come back with you into a brand new ASP Session.


source : knowlegezone.com
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Access classic asp session variables from asp.net"
Thread Thread Starter Forum Replies Last Post
Difference between root session and standard user session in gimp Gajagamini Operating Systems 4 17-01-2011 10:14 AM
Windows 7 console session becomes unresponsive after Remote desktop session Krishanu Networking & Security 4 24-12-2010 06:58 AM
Diffrence between cookies and session variables JEROLD12 Software Development 5 22-12-2009 11:05 PM
Error Message "You do not have access to logon to this session " Francesca Operating Systems 4 27-02-2009 07:46 PM
Session won't stick in Vista IIS 7, classic ASP app Ashish Goenkar Vista Setup and Install 2 03-05-2007 04:46 AM


All times are GMT +5.5. The time now is 12:35 AM.