• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • asp 與 asp.net 共享session

    發表于:2007-06-30來源:作者:點擊數: 標簽:
    這是一個老話題了,因為最近用的到,所以沒辦法又到處找資料。微軟的網站上提供的是用 數據庫 實現的,總覺得太麻煩,也有說直接使用的,但我沒有試成功。我認為直接使用是不可能的。還有一種方法,就是通過幾個頁面轉換,我使用的也是這個方法,通過總結搜索
    這是一個老話題了,因為最近用的到,所以沒辦法又到處找資料。微軟的網站上提供的是用數據庫實現的,總覺得太麻煩,也有說直接使用的,但我沒有試成功。我認為直接使用是不可能的。還有一種方法,就是通過幾個頁面轉換,我使用的也是這個方法,通過總結搜索到的資料,整理后編寫了幾個頁面來轉換。主要是通過隱藏的input來實現的。具體方法如下:

      asp 轉 asp.net 頁面:

         用一個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表單提交。
    代碼中還有要改進的地方也請各位大蝦賜教。


    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>