pages

Tuesday, 23 May 2017

Async and Sessionless controller in Asp.net MVC

I know it's very late and both the concepts are released long back.

Nov 2010 Microsoft released MVC3 RC in which provided a feature for Controller class to be free from session state was provided. Here is a link to Scott Gu's blog releasing same

Scott tells while answering a question on the post: Session state is designed so that only one request from a particular user/session occurs at a time. So if you have a page that has multiple AJAX callbacks happening at once they will be processed in serial fashion on the server. Going session-less means that they would execute in parallel.


Attribute Name is SessionState and it takes Enum of type SessionStateBehaviour which has the following members:

  • Default
  • Disabled
  • ReadOnly
  • Required

Usage:     [SessionState(SessionStateBehavior.Disabled)]

In case you opt to use SessionState attribute TempData and other session related thing won't work as mentioned in a small demo on Dot net curry.

Sessionless Controllers specifies the type of Session support you want for your class. On the other hand, as the name suggests Async Controllers let us perform operations without making the thread wait for completing the operation.

This is a nice blog by an MVP about calling the web services using Normal, Async and Sessionless manner.

Async controllers are deprecated in MVC4 and they are implemented using Task class.  The new model for asynchronous methods is called the Task-based Asynchronous Pattern (TAP), More can be read here about it.

Hope it helps.

No comments:

Post a Comment