为什么Session失去的时候有时候会出现错误

swalia1 2008-08-24 12:39:41
为什么Session失去的时候有时候会出现下面这样而不会自动跳转的登录页面呢?有时候又可以跳转
我Web.config里面的是用<authentication mode="Forms">认证的.<location path="Order">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
是不是应该在Order文件夹里面的文件.cs中再加上什么if(session["Userid"]==null)的语句??要是要加的话应该怎么加??



“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 85: finally
行 86: {
行 87: SqlCommand cmd = new SqlCommand("select count(*) from FlightTick where Userid='" + Session["Userid"].ToString() + "'and OrderTime>'" + DateTime.Today.AddDays(-365) + "' and Status> 1", strcon);
行 88: this.lblRecordCount.Text = Convert.ToString(cmd.ExecuteScalar());
行 89: pagecount = Convert.ToString(ps.PageCount);


源文件: e:\CXET\Order\ManageOrder.aspx.cs 行: 87

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
Order_ManageOrder.GetData() in e:\CXET\Order\ManageOrder.aspx.cs:87
Order_ManageOrder.Page_Load(Object sender, EventArgs e) in e:\CXET\Order\ManageOrder.aspx.cs:21
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
我姓区不姓区 2008-08-24
  • 打赏
  • 举报
回复
为什么不加个Session是否为空的判断呢
swalia1 2008-08-24
  • 打赏
  • 举报
回复
我是用FormsAuthentication.RedirectFromLoginPage跳转的啊.这个都没问题..问题出现在有时候Session失效后刷新页面就出现上面问题..有时候就会跳回到登录页面
amandag 2008-08-24
  • 打赏
  • 举报
回复
使用表单验证验证成功后应该使用FormsAuthentication.RedirectFromLoginPage方法跳转
sunshine_anycall 2008-08-24
  • 打赏
  • 举报
回复
你再finally里干了什么了
swalia1 2008-08-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ojlovecd 的回复:]
为什么不加个Session是否为空的判断呢
[/Quote]
如果为空那应该如何保留当前网址??
zds1010 2008-08-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ojlovecd 的回复:]
为什么不加个Session是否为空的判断呢
[/Quote]
http://www.xpeng.com.cn
http://www.lyyywx.com.cn
http://www.bdgxqsq.com.cn

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧