跨 HttpHandler 保留会话变量
我有一个带有 5 个 .ashx HTTPHandler 的 ASP.NET 应用程序,它们实现 IRequiresSessionState 或 IReadOnlySessionState。
调用第一个处理程序后,我创建一个变量并将其存储在会话中。
当我调用下一个 HttpHandler 时,该变量在会话对象中不可用。
我正在使用 context.Session。
我有一个 global.asax,我在其中检索 sessionId。
有没有办法在 HttpHandler 之间保留会话变量,或者每个处理程序都有自己的会话?
I have an ASP.NET application with 5 .ashx HTTPHandlers that implement IRequiresSessionState or IReadOnlySessionState.
Upon calling the first handler I create a variable and store it in the session.
When I call the next HttpHandler the variable is not available in the session object.
I am use context.Session.
I have a global.asax where I retrieve the sessionId.
Is there a way to preserve session variables across HttpHandlers or does each Handler get its own session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HeartAttack 在这里对此进行了很好的讨论:
http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx
基本上,你需要做类似的事情:
HTH。
这应该维护跨处理程序的会话状态。也就是说,当您登录时,您只有一个会话来处理对该域的所有请求。我建议验证您是否确实登录。缓存当然可以工作,因为这对于所有会话都是通用的,但在服务器上成本更高,因为它不容易消失。
HeartAttack has a good discussion of this here:
http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx
Basically, you need to do something like:
HTH's.
This should maintain session state across handlers. That is, when you log in, you only have one session for all of your requests into that domain. I'd suggest verifying that you are really logged in. Cache of course will work because that is common to all sessions but much more expensive on the server because it does not easily go away.