异步设计中的会话 [英] Sessions in Asynchronous design

查看:28
本文介绍了异步设计中的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个支持 AJAX 的 Web 应用程序,该应用程序向服务器发出多个异步请求.这些服务器请求中的每一个都是长时间运行的服务器任务,每个任务都会向 html 页面返回一个 JSON 对象.这些调用中的每一个都需要对 Session 对象进行读/写访问.

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.

但是当多个异步任务正在处理时,ASP.NET 会锁定会话对象,从而阻止第一个异步调用.所以这些异步调用永远不会并行发生.

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:异步调用是PageMethod调用.

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.

推荐答案

感谢所有为我的问题提供答案和评论的人.我正在总结我的发现和解决方案,以便有人可能会觉得这很有用.

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?

  1. 将 PageMethod 调用更改为实现 IReadOnlySessionState 的 HttpHandler.(就我而言,Ajax 调用只需要对 Session 对象进行读取"访问)
  2. 客户端 JQuery 对服务器 HTTPHandler 进行 Ajax 调用
  3. @Page EnableSessionState 指令可以保留为默认值(读/写)

使用上述解决方案,每次调用读取会话对象时可以进行多次异步调用

With the above solution, multiple async calls are possible with each call reading into the session object

有关对返回 JSON 对象的 HTTP 处理程序进行 Jquery 调用的更多信息,请参阅 链接

For more information about making a Jquery call to a HTTP Handler returning a JSON object, here's the link

这篇关于异步设计中的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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