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表单提交。