在原有的asp程序中用asp.net添加功能模塊,共享SESSIONs是一個難點,下面介紹一種較為簡潔的方法,可以在asp和asp.net中共享session會話。
登錄頁面使用C#重新創建,在成功登錄後執行語句:
Response.Write("<script language='javascript'>window.open('ASPXTOASP.aspx','new');</script>");
打開aspxtoasp.aspx頁面,action設為aspxtoasp.asp,即可將session值post到asp頁面,因為是單向傳遞,不用在其他頁面重復執行動作,經測試,傳遞成功!
Aspxtoasp.aspx代碼如下:
<script language="C#" runat="server">
Response.Write( "<form name=t id=t action=ASPXTOASP.asp 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>");
</script>
Aspxtoasp.asp代碼如下:
<%
for i=1 to Request.Form.Count
Session(Request.Form.Key(i))=Request.Form(i)
next
Response.End
%>
<script language="JavaScript">
window.close();
</script>