首先,我知道存在很多关于会话状态的问题和帖子。设置会话并重新加载页面
只是为了让你知道:我在我的应用程序中使用“MasterPager”。
当我设置会话(“字段”),一切都很好。但是,当我重新加载我的页面(当我回到另一页时),例如Session(“field”)是什么都没有。
我example.aspx页:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' It doesn't works, when I reload, Session is nothing
If Not Session("field") Is Nothing Then
example.Text = Session("field").ToString
End If
End If
End sub
Private Sub ClickButtonActionExample()
Session("field") = "example text"
' It works
example.Text = Session("field").ToString
End Sub
我的web.config:
<sessionState
cookieless="UseCookies"
cookieName=".authz"
mode="StateServer"
regenerateExpiredSessionId="true"
stateConnectionString="tcpip=127.0.0.1:42424"
timeout="20"
useHostingIdentity="true" />
只是为了检查,你知道在你的页面加载代码将只运行一次(在第一次加载),而不是在随后的回发... – Paddy 2014-09-03 15:16:45
是@Paddy。如果我按照每个示例返回其他页面,则会发生此错误。 – guinatal 2014-09-03 15:21:57
你在浏览器中关闭了cookies吗? – Donal 2014-09-03 15:28:14