Sessions in Asynchronous design

后端 未结 2 1550
醉酒成梦
醉酒成梦 2020-12-03 15:06

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

2条回答
  •  -上瘾入骨i
    2020-12-03 16:07

    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. Changed PageMethod call into a HttpHandler implementing IReadOnlySessionState. (In my case, the Ajax call just needs 'read' access into the Session object)
    2. The Client-side JQuery makes the Ajax call to the server HTTPHandler
    3. The @Page EnableSessionState directive can be left to be default (Read/Write)

    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

提交回复
热议问题