当用户遇到特定类型的错误时,在Global.asax上我们更新会话变量IsErrorEncountered,保存会话并将用户重定向回Dashboard页面。在仪表板页面上,当我尝试访问此会话变量时,它不会反映我在Global.asax中所做的更改。为什么会话没有被保存?有人可以告诉我,我是否可以从Global.asax更新我的会话?
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim session As SessionData = HttpContext.Current.Session("SessionData")
sessionData.IsErrorEncountered = True
HttpContext.Current.Session.Add("SessionData", session)
HttpContext.Current.Response.Redirect("~/Dashboard/Index")
End Sub
答案 0 :(得分:0)
重定向可能是您的会话令牌cookie丢失了。尝试使用Response.Redirect方法的重载版本:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim session As SessionData = HttpContext.Current.Session("SessionData")
sessionData.IsErrorEncountered = True
HttpContext.Current.Session("SessionData") = session
HttpContext.Current.Response.Redirect("~/Dashboard/Index", false)
HttpContext.Server.ClearError();
End Sub