· 网络编程· 网页设计· 图形图像· 网站联盟· 数 据 库· 站长时代· 业界资讯· 网站运营· 黑客攻防· 电脑技巧

站长资讯 News
· ASP 专区 · PHP 专区
· JSP 专区 · NET 专区
· XML 专区 · CGI 专区
· 其他相关
热门文章
· FlashMdy快乐行
· 什么是Web3.0
· The World浏览器秘技..
· 游荡在个人网站大潮..
· ASP中Request对象获..
· 今日(2006-11-26)域..
· 实战 FastCGI_2. 安..
· 黑客入侵“在线影院..
· [图文] 认识FrontPag..
· [图文] 谢文写诗袒露..
相关文章
· JavaScript代码可导..
· VB代码:ASP木马后门..
· [图文] 看PDF和Flash..
· Kaspersky推出2006测..
· [图文] 用ASB AntiSp..
· ASP木马Webshell安全..
· ASP中服务器端安全性..
· asp 应用程序的安全..
· 如果防止ASP木马在服..
· 用IIS+ASP建网站的安..
您当前的位置:资源库 -> 网络编程 -> ASP 专区 -> 文章内容
asp 与 asp.net 共享session
作者:无从考证  来源:CSDN  发布时间:2006-4-5 6:59:00  发布人:admin

减小字体 增大字体

用一个asp页,把session信息写到input中,提交给asp.net页
   trans.asp
   <%
    ''----------测试数据--------
    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)
 {
  // ----------测试数据---------
  
  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
'------------------------------------------------------------------------------------------
%>
  代码实现的过程中,asp.net页面提交到asp页的时候不能使用Server.Transfer方法,所以只好用Response.Write来自己写Form表单提交。




 
 
[] [返回上一页] [打 印]