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.

Tuesday 16 May 2017

Difference between Tier and Layers

During an interview this question was asked and I was pretty sure that what ever layers we create in our code (Presentation, BLL, DLL etc) are the tiers but I was wrong.
An answer on stack overflow sums it up very well.
layer = a part of your code, if your application is a cake, this is a slice.
tier = a physical machine, a server.

Scott Hanselman also have a nice blog post on same. He says:
a "Tier" is a unit of deployment, while a "Layer" is a logical separation of responsibility within code.  You may say you have a "3-tier" system, but be running it on one laptop.  You may say your have a "3-layer" system, but have only ASP.NET pages that talk to a database. 

and then he explains about what should be there in your Presentation, BLL and DLL and what should not be there.