3

I'm meeting a problem regarding session-state blocking in ASP.NET web page.

Normally, web-api projects don't have session state. However, as we develop from a legacy projects, web-api 2 module is injected to the old web-form project, and we proceed from there. However, now we detect 2 problems:

  1. The AJAX requests always queue and execute one-by-one. It beats the purpose of concurrent processing
  2. For long-processing requests, the user cannot move on another page, even if he/she doesn't need to know the request result.

The culprit for (1) and (2) is session state blocking. We save authentication information into session state for the web-form projects; and then reuse them on the Web-API controllers. However, as any requests requiring the session, then they execute one-by-one, and for long requests, new request cannot come in even if the user already leave that page (the session is still blocked)

I have checked several answers from related issues, and it seems I'm not alone:

  1. This question informs about the situation clearly, however didn't provide a clear solution (for Web-API case)
  2. This question also give good advises about using Read-only session which does not block concurrency. However, we still not find out how to do with WebAPI controllers inside Web-form project.
  3. According to MVC documents, we can disable session state by adding attribute [System.Web.Mvc.SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] on controllers' level. However it didn't work (as expected, because we have here Web-API controllers). Unfortunately, I didn't find similar attributes/any mechanism for web-api controllers.

I also check: in PHP case, they have the same issue, yet they can release the session lock early if they want to.

Therefore I'm wondering:

  1. Is there a way to disable session for certain Web-API actions/controllers?
  2. Is there a way to release the lock on session early, when we don't need it any more?
Community
  • 1
  • 1
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124

1 Answers1

0

Dot Net serializes session state by default. You can decorate your class with a session modifier so that it can be accessed asynchronously without session state.

This works in cases where the client is java or jquery and they are polling your controller. The controller will release later than sooner. To make it more predictable place this specified on your class:

[SessionState(SessionStateBehavior.ReadOnly)]
function Do()
{
}
Ross Bush
  • 14,648
  • 2
  • 32
  • 55
  • 1
    hi, is your SessionState from System.Web.Mvc? I have problem with Web-Api controllers. I already tried add [System.Web.Mvc.SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] and it doesn't work. – Hoàng Long May 09 '16 at 02:50