救命!!!Session传递不了!
问题如下:
我在登陆页面验证用户名、密码、验证码通过后给Session赋了值:
……
Session[ "user_asfang "]=zh.Text;(zh控件输入的值是zhaoguo2002)
Response.Redirect( "menu.aspx ");
……
转到了menu.aspx中,Session[ "user_asfang "]变量却不起作用!
public void Page_Load(Object sender,EventArgs e)
{
……
string sqlstring= "select * from user_asfang where yhm= ' "+Session[ "user_asfang "].ToString()+ " ' ";
SqlCommand comm=new SqlCommand(sqlstring,conn);
rd=comm.ExecuteReader();
}
比如我原先输入的用户名为zhaoguo2002
但是传递到menu.aspx中的Session[ "user_asfang "]变量的值好象是空值~但是Session[ "user_asfang "]变量是存在的,只是
string sqlstring= "select * from user_asfang where yhm= ' "+Session[ "user_asfang "].ToString()+ " ' ";这句达不到
string sqlstring= "select * from user_asfang where yhm= 'zhaoguo2002 ' ";这句的效果了!为什么啊?郁闷死!!!
------解决方案--------------------1、设置断点DEBUG
2、在Page_Load里写
if(Session[ "user_asfang "]==null)
Response.Write( "Session is Null ");
else
Response.Write( "Session[\ "user_asfang\ "] is "+Session[ "user_asfang "].ToString());
Response.End();
以上方法任选