ASP to ASP.NET Session

D

Dimiter Andonov

Hi guys,

Here is the situation I'm fighting for two days without any success:
I work on a part of classic ASP application that has to be migrated to
ASP.NET. I know that ASP session variables cannot be directly accessed
in ASP.NET and vice versa. So, I have designed four pages in order to
transfer the session state in both directions (ASP to ASP.NET, ASP.NET
to ASP).
Here are those pages:

1. ASP to ASP.NET
a) ASPtoASPNET.asp
<%
Response.Write("<form name=t id=t action=ASPtoASPNET.aspx method=post
Response.Write("<input type=hidden name=DestPage" & " value=" &
Request.QueryString("target") & ">")
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>")
%>

b) ASPtoASPNET.aspx

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.ToString();
}
Server.Transfer(Session("destpage").ToString());
}

2. ASP.NET to ASP
a) ASPNETtoASP.aspx

private void Page_Load(object sender, System.EventArgs e)
{
string destpage = Request.QueryString["destpage"];

Response.Write("<form name=t id=t action=ASPNETtoASP.asp?destpage=" +
destpage + " method=post>");

foreach(object it in Session.Contents)
{
Response.Write("<input type=hidden name=" + it.ToString());
Response.Write(" value=" + Session[it.ToString()].ToString() + "
}

Response.Write("</FORM>");
Response.Write("<scr" + "ipt>t.submit();</scr" + "ipt>");
}

b) ASPNETtoASP.asp

<%

url = Request.QueryString("destpage")
Response.Write("<form name=t id=t action=" & url & "
method=post></form>")

for i = 1 to Request.Form.Count
Session(Request.Form.Key(i)) = Request.Form(i)
Response.write( i & ": " & Request.Form.Key(i) & ": " &
Request.Form(i) & "<BR>")
next

Response.Write("<script>t.submit();</script>")
%>


The problem is that session is lost randomly without any pattern. To
make my life even worse that happens only on the production
environment (I have no control there). On my test environment
everything is just fine.
Have anyone any idea what's wrong?

Thank you in advance,
Dimiter Andonov
 
S

Sherif ElMetainy

Hello

I think this can happen when the user uses the browser back/forward button
instead browsing using links. For example the user is in the ASP part, goes
to the ASP.NET part, where his session is transferred, then the ASP.NET part
sets a session variable, then the user goes to the ASP part with the back
button. The new value is not transferred to ASP part. Of course you can't
disable the back/forward buttons in the user's browser.

The only solutions that I can think of are:
1- Don't use sessions, use cookies and store information somewhere both
parts have access to such as a database.
2- Let ASP.NET handle ASP pages ( can be changed from IIS), in this case
the whole application will be .NET, but you may encouter compatibility
problems between ASP and ASP.NET

Best regards,
Sherif

Dimiter Andonov said:
Hi guys,

Here is the situation I'm fighting for two days without any success:
I work on a part of classic ASP application that has to be migrated to
ASP.NET. I know that ASP session variables cannot be directly accessed
in ASP.NET and vice versa. So, I have designed four pages in order to
transfer the session state in both directions (ASP to ASP.NET, ASP.NET
to ASP).
Here are those pages:

1. ASP to ASP.NET
a) ASPtoASPNET.asp
<%
Response.Write("<form name=t id=t action=ASPtoASPNET.aspx method=post
Response.Write("<input type=hidden name=DestPage" & " value=" &
Request.QueryString("target") & ">")
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>")
%>

b) ASPtoASPNET.aspx

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.ToString();
}
Server.Transfer(Session("destpage").ToString());
}

2. ASP.NET to ASP
a) ASPNETtoASP.aspx

private void Page_Load(object sender, System.EventArgs e)
{
string destpage = Request.QueryString["destpage"];

Response.Write("<form name=t id=t action=ASPNETtoASP.asp?destpage=" +
destpage + " method=post>");

foreach(object it in Session.Contents)
{
Response.Write("<input type=hidden name=" + it.ToString());
Response.Write(" value=" + Session[it.ToString()].ToString() + "
}

Response.Write("</FORM>");
Response.Write("<scr" + "ipt>t.submit();</scr" + "ipt>");
}

b) ASPNETtoASP.asp

<%

url = Request.QueryString("destpage")
Response.Write("<form name=t id=t action=" & url & "
method=post></form>")

for i = 1 to Request.Form.Count
Session(Request.Form.Key(i)) = Request.Form(i)
Response.write( i & ": " & Request.Form.Key(i) & ": " &
Request.Form(i) & "<BR>")
next

Response.Write("<script>t.submit();</script>")
%>


The problem is that session is lost randomly without any pattern. To
make my life even worse that happens only on the production
environment (I have no control there). On my test environment
everything is just fine.
Have anyone any idea what's wrong?

Thank you in advance,
Dimiter Andonov
 
D

Dimiter Andonov

Hello Sherif, thank you for your reply.
However, there is no Back Button involved here - all navigation is
made either through form posting or Response.Redirect (or following a
link, of course). I have already resolved the situation using cookies,
but I am still curious why I am losing the session from time to time -
there is no pattern that could be debugged - all this happens
randomly.
Thank you again for your time.

Sherif ElMetainy said:
Hello

I think this can happen when the user uses the browser back/forward button
instead browsing using links. For example the user is in the ASP part, goes
to the ASP.NET part, where his session is transferred, then the ASP.NET part
sets a session variable, then the user goes to the ASP part with the back
button. The new value is not transferred to ASP part. Of course you can't
disable the back/forward buttons in the user's browser.

The only solutions that I can think of are:
1- Don't use sessions, use cookies and store information somewhere both
parts have access to such as a database.
2- Let ASP.NET handle ASP pages ( can be changed from IIS), in this case
the whole application will be .NET, but you may encouter compatibility
problems between ASP and ASP.NET

Best regards,
Sherif

Dimiter Andonov said:
Hi guys,

Here is the situation I'm fighting for two days without any success:
I work on a part of classic ASP application that has to be migrated to
ASP.NET. I know that ASP session variables cannot be directly accessed
in ASP.NET and vice versa. So, I have designed four pages in order to
transfer the session state in both directions (ASP to ASP.NET, ASP.NET
to ASP).
Here are those pages:

1. ASP to ASP.NET
a) ASPtoASPNET.asp
<%
Response.Write("<form name=t id=t action=ASPtoASPNET.aspx method=post
Response.Write("<input type=hidden name=DestPage" & " value=" &
Request.QueryString("target") & ">")
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>")
%>

b) ASPtoASPNET.aspx

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.ToString();
} Server.Transfer(Session("destpage").ToString());
}

2. ASP.NET to ASP
a) ASPNETtoASP.aspx

private void Page_Load(object sender, System.EventArgs e)
{
string destpage = Request.QueryString["destpage"];

Response.Write("<form name=t id=t action=ASPNETtoASP.asp?destpage=" +
destpage + " method=post>");

foreach(object it in Session.Contents)
{
Response.Write("<input type=hidden name=" + it.ToString());
Response.Write(" value=" + Session[it.ToString()].ToString() + "
}

Response.Write("</FORM>");
Response.Write("<scr" + "ipt>t.submit();</scr" + "ipt>");
}

b) ASPNETtoASP.asp

<%

url = Request.QueryString("destpage")
Response.Write("<form name=t id=t action=" & url & "
method=post></form>")

for i = 1 to Request.Form.Count
Session(Request.Form.Key(i)) = Request.Form(i)
Response.write( i & ": " & Request.Form.Key(i) & ": " &
Request.Form(i) & "<BR>")
next

Response.Write("<script>t.submit();</script>")
%>


The problem is that session is lost randomly without any pattern. To
make my life even worse that happens only on the production
environment (I have no control there). On my test environment
everything is just fine.
Have anyone any idea what's wrong?

Thank you in advance,
Dimiter Andonov
 

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

Top