時(shí)間:2015-06-28 00:00:00 來(lái)源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(0)
在原有的asp程序中用asp.net添加功能模塊,共享SESSIONs是一個(gè)難點(diǎn),下面介紹一種較為簡(jiǎn)潔的方法,可以在asp和asp.net中共享session會(huì)話。
登錄頁(yè)面使用C#重新創(chuàng)建,在成功登錄后執(zhí)行語(yǔ)句:
Response.Write("");
打開(kāi)aspxtoasp.aspx頁(yè)面,action設(shè)為aspxtoasp.asp,即可將session值post到asp頁(yè)面,因?yàn)槭菃蜗騻鬟f,不用在其他頁(yè)面重復(fù)執(zhí)行動(dòng)作,經(jīng)測(cè)試,傳遞成功!
Aspxtoasp.aspx代碼如下:
Response.Write( "
");Response.Write("");
Aspxtoasp.asp代碼如下:
<%
for i=1 to Request.Form.Count
Session(Request.Form.Key(i))=Request.Form(i)
next
Response.End
%>
window.close();
這是一個(gè)老話題了,因?yàn)樽罱玫牡?,所以沒(méi)辦法又到處找資料。微軟的網(wǎng)站上提供的是用數(shù)據(jù)庫(kù)實(shí)現(xiàn)的,總覺(jué)得太麻煩,也有說(shuō)直接使用的,但我沒(méi)有試成功。我認(rèn)為直接使用是不可能的。還有一種方法,就是通過(guò)幾個(gè)頁(yè)面轉(zhuǎn)換,我使用的也是這個(gè)方法,通過(guò)總結(jié)搜索到的資料,整理后編寫(xiě)了幾個(gè)頁(yè)面來(lái)轉(zhuǎn)換。主要是通過(guò)隱藏的input來(lái)實(shí)現(xiàn)的。具體方法如下:
asp 轉(zhuǎn) asp.net 頁(yè)面:
用一個(gè)asp頁(yè),把session信息寫(xiě)到input中,提交給asp.net頁(yè)
trans.asp
<%
’’----------測(cè)試數(shù)據(jù)--------
session("name")="srx"
session("id")="1"
session("sex")="f"
session("pass")="asdfas"
session("age")="23"
session("weight")="131"
’’--------------------------
Response.Write("
") Response.Write("
%>
#p#副標(biāo)題#e#
asptoaspx.aspx
<%@ Page language="c#" %>
private void Page_Load(object sender, System.EventArgs e)
{
Session.Timeout = 60;
for(int i=0;i { Session[Request.Form.GetKey(i)]=Request.Form[i].ToString(); } allsession(); //輸出所有的Session,使用時(shí)可注釋掉 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 variables "); foreach(object obj in Session.Contents) { Response.Write("Session["+obj.ToString()+"] - "+Session[obj.ToString()].ToString()+" } } asp.net 轉(zhuǎn) asp 頁(yè)面: 用一個(gè)asp.net頁(yè),把session信息寫(xiě)到input中,提交給asp頁(yè) trans.aspx <%@ Page language="c#" %> private void Page_Load(object sender, System.EventArgs e) { // ----------測(cè)試數(shù)據(jù)--------- Session["name"] = "srx"; Session["sex"]="F"; //---------------------------- Response.Write("
");//輸出所有的Session,使用時(shí)可注釋掉
foreach(object obj in Session.Contents)
{
Response.Write("
Response.Write(" value = ’"+Session[obj.ToString()].ToString()+"’>");
}
try
{
if(Request.QueryString["DestPage"].ToString().Length > 4 )
{
Response.Write("
Response.Write(" value = ’"+Request.QueryString["DestPage"].ToString()+"’>");
}
}
#p#副標(biāo)題#e#
catch{}
Response.Write("");
Response.Write("
}
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() ’使用時(shí)注釋掉此行代碼即可
function allsession()
Response.Write "There are " & Session.Contents.Count &" Session variables
"
Dim strName, iLoop
For Each strName in Session.Contents’使用For Each循環(huán)察看Session.Contents
If IsArray(Session(strName)) then ’如果Session變量是一個(gè)數(shù)組? ’循環(huán)打印數(shù)組的每一個(gè)元素
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
Response.Write strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "
"
Next
Else ’其他情況,就簡(jiǎn)單打印變量的值
Response.Write strName & " - " & Session.Contents(strName) & "
"
End If
Next
end function
’--------------------------------------------
%>
關(guān)鍵詞標(biāo)簽:ASP,ASP.Net,共享,Ses
相關(guān)閱讀
熱門(mén)文章 誅仙3飛升任務(wù)怎么做-誅仙3飛升任務(wù)流程最新2022 鐘離圣遺物推薦-原神鐘離圣遺物詞條 解決方法:應(yīng)用程序“DEFAULT WEB SITE”中的服務(wù)器錯(cuò)誤 使用aspnet_regiis.exe 重新注冊(cè).NET Framework
人氣排行 誅仙3飛升任務(wù)怎么做-誅仙3飛升任務(wù)流程最新2022 asp.net表單提交方法GET\POST 在ASP.NET中如何判斷用戶IE瀏覽器的版本 Asp.net中messagebox的實(shí)現(xiàn)方法 Asp.net中的web.config配置 在ASP.NET MVC中實(shí)現(xiàn)大文件異步上傳 asp.net獲取URL和IP地址 FileUpload上傳多文件出現(xiàn)錯(cuò)誤的解決方法