从会话 Cookie 实例化 ASP.NET 会话

发布于 2024-08-05 06:49:16 字数 135 浏览 5 评论 0原文

是否可以从会话 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅听莫相离 2024-08-12 06:49:16

据我所知,由于页面生命周期,这是不可能的。在生命周期完成并启动会话之前,除了将所需的信息存储在应用程序变量中或使用 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

讽刺将军 2024-08-12 06:49:16

不,我不认为,因为它发生在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文