从会话 Cookie 实例化 ASP.NET 会话
是否可以从会话 cookie 实例化会话?我有一个场景,(由于管道)我有可用的 cookie,但我的 ASP.NET Http Context 尚未构造 Context.Session 对象。我可以手动执行此操作,以某种方式引用 cookie 或其内容吗?
is it possible to instantiate a session from a session cookie? I have a scenario, where (due to pipeline) I have the cookie available, but I my ASP.NET Http Context did not construct the Context.Session object yet. Can I do this manually, referencing the cookie or its contents somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,由于页面生命周期,这是不可能的。在生命周期完成并启动会话之前,除了将所需的信息存储在应用程序变量中或使用 HttpCookie 写入单独的 cookie 之外,您无能为力。
如果我需要在会话初始化之前执行某些操作,我通常会使用后者。
我假设您需要获取存储在会话中的信息或需要会话 ID
As far as I am aware this is not possible due to the page lifecycle. Until the lifecycle completes and initaties the Session there isn't much you can do, apart from either storing the information you need in an Application Variable, or alternatively writing a seperate cookie using HttpCookies.
I normally use the latter if I need to do something before the Session is initialized.
I am assuming you need to get information which is stored in the Session or requires the Session Id
不,我不认为,因为它发生在 SessionStateModule 内部,即使您尝试创建,您也无法访问存储的实际变量。但是,有 Session_OnStart 事件,您可以在其中执行 sessoin 访问代码。
No I dont think because it happens inside SessionStateModule and even if you try to create you will not get access to actual variables stored. However there is Session_OnStart event where you can do your sessoin access code.