日期:2014-05-18  浏览次数:20774 次

求救!session 传递问题
原先的页面是asp   用的数据库是access,我现在想用.net做几个新页加上去

为什么在aspx中直接取原页面的session是不好用的啊?难道不能传递吗?小弟菜鸟,大虾快救救吧!!

------解决方案--------------------
主要是通过隐藏的input来实现的。具体方法如下:
<%

Username=Request.Form( "Username ")
Password=Request.Form( "Password ")
Set Rs = Server.CreateObject( "ADODB.Recordset ")
sql= "select * from teacher where Uname= ' "&Username& " ' and Pwd= ' "&Password& " ' "
rs.open sql,cn,1,1
if rs.bof or rs.eof then
Response.write( " <script> alert( '用户名或密码错误!请返回重新输入 ');window.location.replace( 'default.asp '); </script> ")
Response.End()
else
session( "Username ")=trim(Rs( "Uname "))


response.write( " <form name=frm id=frm action= " "asptoaspx.aspx " " method=post > ")
Response.Write " <input type=hidden name=uname value= "&session( "Username ")& "> "
Response.Write " <input type=hidden name=flag value=1 "> " //此处用来判断登陆还是退出
response.write( " </form> ")
response.write( " <scr " + "ipt> frm.submit(); </scr " + "ipt> ")
%>


asptoaspx.aspx


<%@ Page Language= "C# " ContentType= "text/html " ResponseEncoding= "gb2312 " %>
<script runat= "server ">
protected void Page_Load(object sender, EventArgs e)
{

string flag = Request.Form.Get( "flag ");
if (flag == "1 ")
{

Session[ "teacher "] = Request.Form.Get( "uname ");

}
else
{

Session[ "teacher "] = " ";
}


Response.Redirect( "http://127.0.0.1/show ");
}

</script>
asp.net 转 asp 页面:

logincheck.aspx

<%@ Page language= "c# " %>
<script language=C# runat=server>
private void Page_Load(object sender, System.EventArgs e)
{

Session[ "teacher "] = uname.Text.Trim().ToString();
Response.Write( " <form name=frm id=frm action=aspxtoasp.asp method=post> ");
Response.Write( " <input type=hidden name=username value= ' "+Session[ "teacher "]+ " '> ");
Response.Write( " <input type=hidden name=flag value=1> ");
Response.Write( " </form> ");
Response.Write( " <scr "+ "ipt language= 'javascript '> frm.submit(); </scr "+ "ipt> ");
}
</script>


aspxtoasp.asp


程序代码
<%

flag=request( "flag ")
if flag= "1 " then
session( "teacher ")= " "
else
session( "teacher ")=request( "username ")
end if

Response.Redirect "xxx.aspx "

%>


代码差不多就是这个样子

资料来源:http://www.zjidea.com/blog/article.asp?id=251



------解决方案--------------------
你用url的形式不好?
a.aspx?id=你的值
------解决方案--------------------
在html中写,在后台用,可能出现页面控件未加载完成,session就取不到值.