asp 與 asp.net 共享session
發(fā)表時間:2024-06-07 來源:明輝站整理相關軟件相關文章人氣:
[摘要]用一個asp頁,把session信息寫到input中,提交給asp.net頁 trans.asp <% ''----------測試數(shù)據(jù)-------- session("name")="srx" sessio...
用一個asp頁,把session信息寫到input中,提交給asp.net頁
trans.asp
<%
''----------測試數(shù)據(jù)--------
session("name")="srx"
session("id")="1"
session("sex")="f"
session("pass")="asdfas"
session("age")="23"
session("weight")="131"
''--------------------------
Response.Write("<form name=frm id=frm action=""asptoaspx.aspx"" method=post >")
for each Item in Session.Contents
Response.Write("<input type=hidden name=" & Item)
Response.Write( " value=" & Session(item) & " >")
next
if len(Request.QueryString("Destpage")) >4 then
Response.Write("<input type=hidden name=DestPage value=" & Request.querystring("DestPage") & ">")
end if
Response.Write("</FORM>")
Response.Write("<scr" + "ipt>frm.submit();</scr" + "ipt>")
%>
asptoaspx.aspx
<%@ Page language="c#" %>
<script language=C# runat=server>
private void Page_Load(object sender, System.EventArgs e)
{
Session.Timeout = 60;
for(int i=0;i<Request.Form.Count;i++)
{
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();
}
allsession(); //輸出所有的Session,使用時可注釋掉
try
{
if( Session["DestPage"].ToString().Length >4 )
{
Server.Transfer(Session["DestPage"].ToString(),true);
}
}
catch {}
}
private void allsession()
{
Response.Write ("There are " + Session.Contents.Count +" Session <I>var</I>iables<P>");
foreach(object obj in Session.Contents)
{
Response.Write("Session["+obj.ToString()+"] - "+Session[obj.ToString()].ToString()+"<br>");//輸出所有的Session,使用時可注釋掉
}
}
</script>
asp.net 轉 asp 頁面:
用一個asp.net頁,把session信息寫到input中,提交給asp頁
trans.aspx
<%@ Page language="c#" %>
<script language=C# runat=server>
private void Page_Load(object sender, System.EventArgs e)
{
// ----------測試數(shù)據(jù)---------
Session["name"] = "srx";
Session["sex"]="F";
//----------------------------
Response.Write("<form name=frm id=frm action=aspxtoasp.asp method=post>");
foreach(object obj in Session.Contents)
{
Response.Write("<input type=hidden name='"+obj.ToString()+"'");
Response.Write(" value = '"+Session[obj.ToString()].ToString()+"'>");
}
try
{
if(Request.QueryString["DestPage"].ToString().Length > 4 )
{
Response.Write("<input type=hidden name='DestPage'");
Response.Write(" value = '"+Request.QueryString["DestPage"].ToString()+"'>");
}
}
catch{}
Response.Write("</form>");
Response.Write("<scr"+"ipt language='javascript'>frm.submit();</scr"+"ipt>");
}
</script>
aspxtoasp.asp
<%
for i=1 to Request.Form.Count
Session(Request.Form.Key(i))=Request.Form(i)
next
if Len(Session("DestPage")) >4 then
Response.Redirect(Session("DestPage"))
end if
'-----------------------輸出所有的Session------------------------------------------------
call allsession() '使用時注釋掉此行代碼即可
function allsession()
Response.Write "There are " & Session.Contents.Count &" Session <I>var</I>iables<P>"
Dim strName, iLoop
For Each strName in Session.Contents'使用For Each循環(huán)察看Session.Contents
If IsArray(Session(strName)) then '如果Session變量是一個數(shù)組? '循環(huán)打印數(shù)組的每一個元素
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
Response.Write strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "<BR>"
Next
Else '其他情況,就簡單打印變量的值
Response.Write strName & " - " & Session.Contents(strName) & "<BR>"
End If
Next
end function
'------------------------------------------------------------------------------------------
%>
代碼實現(xiàn)的過程中,asp.net頁面提交到asp頁的時候不能使用Server.Transfer方法,所以只好用Response.Write來自己寫Form表單提交。