如何在HttpHandler中使用ASP.NET会话状态? [英] How to use ASP.NET Session State in an HttpHandler?

查看:119
本文介绍了如何在HttpHandler中使用ASP.NET会话状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在客户端页面(跨域,不在我们的IIS服务器等)上的HttpHandler,当他们单击我们的嵌入式链接时,它将触发我们服务器上的Handler.到目前为止,一切正常.

I have an HttpHandler that is run on a client page (cross domain, not on our IIS server, etc) and when they click on our embedded link it fires off the Handler on our server. So far everything is working normally.

我现在正在尝试使用System.Web.HttpContext.Session对象,但它为null.我以为它是null,因为在调用HttpHandler之前我们没有会话?并且多次调用处理程序将为每个调用创建一个新会话?如果是这种情况,MS是否只是在调用HttpHandler时禁用了Session对象?有人可以确认吗?

I am now trying to use the System.Web.HttpContext.Session object but it is null. I am thinking it is null because we don't have a session until our HttpHandler is invoked? And multiple calls to the handler will create a new session per call? If this is the case did MS just disable the Session object when calling into a HttpHandler? Can anyone confirm this?

在这种情况下,您如何维护呼叫之间的状态?某种基于SQL的数据对象?一个文件?

If this is the case, what do you do to maintain state between calls? Some sort of SQL based data object? A file?

TIA

推荐答案

让您的HttpHandler实现 IRequiresSessionState 接口.它将启用会话状态使用. 可以在System.Web.SessionState命名空间中找到IRequiresSessionState.

Have your HttpHandler implement the IRequiresSessionState interface. It will enable session state use. IRequiresSessionState can be found in the System.Web.SessionState namespace.

这篇关于如何在HttpHandler中使用ASP.NET会话状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆