无法读取更改的会话值? [英] Cannot Read Changed Session Value?

查看:73
本文介绍了无法读取更改的会话值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是这里的新生..我想问一下关于Session的事情。会话只能读一次吗?如果你将它改成新值,它将无法在其他页面中读取?


场景..

我有页面A和页面B.我指定一个新的会话(购物车)= 1.然后我可以在页面B中读到会话(购物车)= 1.


由于某种原因,我已经更改了页面A中的会话(购物车)= 2.然后我再次回到页面B.当我阅读页面B中的会话(购物车)时,它仍然包含旧的值1.


会话实际上是否有效?有没有解决问题?


感谢您的帮助..

Hi guys, i am a freshman here.. I would like to ask a things about Session.. Does session only work to be read for once? and if you change it into new value, it will not be able to be read in other page?

Scenario..
I have page A and Page B. I assign a new Session("cart") = 1. Then I can read in Page B that Session("cart") = 1.

Due to some reason, I have changed the Session("cart") = 2 in page A. Then i go back to Page B again. When I read the Session("cart") in Page B, it still contain the old value which is 1.

Is that the Session actually work? Is there anyway to solve the problem?

Thanks for any help..

推荐答案

您确定自己在同一会话?并且不会意外地有两个?


您的代码是什么样的?如果它是同一个会话,您应该可以根据需要进行更改和查看。
Are you sure you are in the same session? And don''t accidently have two?

What does your code look like? If it is the same session you should be able to make changes and view as many times as you want.


感谢您的回复...


是的我确定..这是我的代码片段......


===================== ======页面A ========================

如果是IsNothing(会话(购物车)) )然后

Dim sql As String

sql = #SQL CODE HERE#

cart = GetListRecord(sql)< ---- A返回ArrayList的方法

Session(" cart")= cart< ----会话分配

Else< ---------- - 这部分是向Arraylist添加更多数据

Dim tempCart As New ArrayList

tempCart = Session(" cart")

Dim sql作为String

sql = #SQL CODE#

tempcart = AddToCart(SQL,tempCart)< ---返回添加购物车

Session( &q uot; cart")= tempCart

结束如果



============= ============第B页========================


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load

Alert(Session.Item(" Cart")。count())< - - Arraylist中提示的项目数量

结束子


* NB警告(* String *)< ----是一种方法我以前在ASP上提示......

================================= ================= ======


第一次作业,我可以在PAge B中阅读...但是当我回到页面A,然后更改会话值,然后返回到页面B,它仍然提示旧值...


感谢您的回复...
Thank for your reply...

Yeah i am sure.. here is piece of my code...

===========================Page A========================
If IsNothing(Session("cart")) Then
Dim sql As String
sql = #SQL CODE HERE#
cart = GetListRecord(sql) <---- A method that return ArrayList
Session("cart") = cart <---- Session Assignment
Else <----------- this part is to add more data to Arraylist
Dim tempCart As New ArrayList
tempCart = Session("cart")
Dim sql As String
sql = #SQL CODE#
tempcart = AddToCart(SQL,tempCart) <--- return added cart
Session("cart") = tempCart
End If



=========================PAGE B========================

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Alert(Session.Item("Cart").count()) <--- prompt number of item in Arraylist
End Sub


*NB alert(*String*) <---- is a method i used to prompt on ASP...
================================================== ======

for the first assignment, i can read in PAge B... but when i go back to page A, then changed the session value, then go back to page B, it still prompt old value...

Thank for your reply...


不会将会话项作为对象返回?当你得到计数时,它会计算该会话项中有多少个对象(说实话,这看起来似乎不是正确的代码)并且应该是一个数组。如果你把它投射到一个数组,然后检索计数,它应该给你正确的值。


虽然,然后,我可能会离开。
Aren''t session items returned as objects? When you get the count, it is counting how many objects there are in that session item (which, to be honest, doesn''t seem like correct code to begin with) and that should be one, an array. If you cast it to an array, then retrieved the count, it should give you the correct value.

Although, then again, I could be way off.


这篇关于无法读取更改的会话值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆