.net 页面跳转,本机正常,服务器上就不正常了
代码如下:
indexqx.aspx的代码
protected void Page_Load(object sender, EventArgs e)
{
if ((bool)Session["emp_loginok"])
{
}
else
{
Response.Redirect("loginqx.aspx");
}
}
loginqx.aspx代码
protected void LoginB_Click(object sender, EventArgs e)
{
.
.
.
.
//对密码与帐号的判断
Session["emp_loginok"] = true;
Response.Redirect("indexqx.aspx");
}
Global.asax中代码:
void Session_Start(object sender, EventArgs e)
{
Session["emp_loginok"] = false;
}
在自己的机子上可以很正常的跳转,但到了服务器上,就出了问题.
问题的现象是:当密码与帐号输入正确后,但总是跳不到indexqx.aspx页面.
还请各位前辈们帮下忙!
[解决办法]
indexqx.aspx的代码
protected void Page_Load(object sender, EventArgs e)
{
if ((bool)Session["emp_loginok"])
{
}
else
{
Response.Redirect("loginqx.aspx");
}
}
loginqx.aspx代码
protected void LoginB_Click(object sender, EventArgs e)
{
.
.
.
.
//对密码与帐号的判断
Session["emp_loginok"] = true;
this.Response.Write(Session["emp_loginok"].ToString());
看看这里打印出来有没有值,没有或者报错的话,就是 Session 没有写入。
Response.Redirect("indexqx.aspx");
}
Global.asax中代码:
void Session_Start(object sender, EventArgs e)
{
Session["emp_loginok"] = false;
}
[解决办法]
应该没问题,Session里面存Bool类型的,ToString()出来就是"true" or "false"
不过由于系统或IIS的不一样,还是ToString()出来看看,楼主应该是XP吧
[解决办法]
以后尽量不要用SESSION 学习一下用VIEWSTATE,用法和SESSION差不多,但是不会出现莫名其妙的问题。
[解决办法]
Session变量的有效期是不定的,即使是设定了超时时间好像也不起作用。
当服务器繁忙的时候,Session经常会丢失。
所以在使用session的时候,经常要判断Session[["emp_loginok"] == null,
才能继续下去,不判断而使用Session会报错。
你想页面之见传值用其他方法,用URL或者其他,
若只是想在当前页面保留值,用viewstate.
[解决办法]
[解决办法]
只用
Response.Write(Session["trytry"].ToString());
的话能正常显示出"中华人民共和国"
但加上
Response.Write(Session["emp_loginok"].ToString());
后就出现了下能的提示
“/bdqx”应用程序中的服务器错误。
--------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
trytry.Button1_Click(Object sender, EventArgs e) +104
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
--------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433
====================
很明显,session里面没有被赋值。可以断点调试一下。
[解决办法]
URL传值吧,Session不稳定吧.
[解决办法]
首先是服器上的文件有有你自己系上的文件,比如更改后的GLOBAL.ASAX中,有有一起拷去,以及一些自己的代文件等。
其次是你的目路,服器上路肯定和你的XP上的不一。
Response.Write(Session["emp_loginok"].ToString());
SESSION量有值,不管是在你的indexqx.aspx和loginqx.aspx
都有emp_loginok量的初值。以及哪里取。
[解决办法]
显然是Session["emp_loginok"]为空了
为空时,不能进行ToString操作
Session默认是30分钟有效时间
[解决办法]
先判断session是不是为null
if(Session["emp_loginok"]==null)
{
//Session["emp_loginok"]=yourkey;
}
else
{
yourstr=Session["emp_loginok"].Tostring();
}