异步设计中的会话
我们正在构建一个支持 AJAX 的 Web 应用程序,该应用程序向服务器发出多个异步请求。这些服务器请求中的每一个都是长时间运行的服务器任务,每个请求都会将 JSON 对象返回到 html 页面。每个调用都需要对 Session 对象进行读/写访问。
但是当多个异步任务正在进行时,ASP.NET 会锁定会话对象,从而阻塞第一个异步调用。因此这些异步调用永远不会并行发生。
PS:异步调用是PageMethod调用。
当与异步调用一起使用时,首先“不”建议使用会话。关于设计此异步请求模型的任何其他建议将受到高度赞赏。
We are building a AJAX enabled web application that makes multiple asynchronous requests to the server. Each of these server requests are long running server tasks with each returning back a JSON object to the html page. Each of these calls need read/write access to the Session object.
But the ASP.NET locks the session object when multiple asynchronous tasks are in process, thus blocking the first asynchronous call. So these asynchronous calls never happen in parallel.
PS: The asynchronous calls are PageMethod calls.
Are Sessions are 'not' recommended in the first place when used along-side asynchronous calls. Any other suggestions on designing this asynchronous request model will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢所有对我的问题发表答案和评论的人。我正在总结我的发现和解决方案,以便有人可能会发现这很有用。
每个发表评论的人都正确地建议不要在异步调用中使用会话。那么,我是如何解决这个问题的呢?
)在上述解决方案中,每次调用都可以读取会话对象,从而进行多个异步调用
有关对返回 JSON 对象的 HTTP 处理程序进行 Jquery 调用的更多信息,请参阅 链接
Thanks to everyone that posted answers and comments to my question. I'm summing up my findings and solution so that someone may find this useful.
Everyone that commented is correct about recommending not to use Sessions in asynchronous calls. So, how did I get around it?
With the above solution, multiple async calls are possible with each call reading into the session object
For more information about making a Jquery call to a HTTP Handler returning a JSON object, here's the link
我实际上同意在使用异步调用时不建议使用会话,事实上在任何情况下会话的使用都应该最少。我的大多数应用程序根本不直接使用会话状态,除非内部会员资格要求。
I would actually agree that sessions are not recommended when using asynchronous calls, in fact use of sessions should be minimal in any case. Most of my apps don't use sessionstate directly at all, except what's required by the Membership stuff internally.