ASP和ASP.Net共享Session解决办法

发布时间:2020-02-28编辑:脚本学堂
ASP和ASP.Net共享Session解决办法

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) 

// ----------测试数据--------- 
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循环察看Session.Contents 
 If IsArray(Session(strName)) then ’如果Session变量是一个数组? ’循环打印数组的每一个元素 
  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 
’-------------------- 
%>