开发者

What's the advantage of using Session-less Controllers in ASP.NET MVC3? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
开发者_StackOverflow社区

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 5 years ago.

Improve this question

Can anyone get me a detailed answer on this?

What's the advantage of using Session-less Controllers in ASP.NET MVC?


If you have a Session-less Controller then you will be able service simultaneous requests from the same browser instance. Otherwise, ASP.NET will queue up the requests as they are received in order to give them sequential access to the ASP.NET Session object, to avoid deadlock issues or other race conditions.

You can actually have 1 request to a 'Session-ful' Controller and multiple requests to 'Session-less' Controllers simultaneously. This pattern has been useful to me in implementing a long-running process (implemented through a 'Session-ful' AsyncController) with AJAX calls from the client to a 'Session-less' Controller which provides the user with updates as to how far through the long-running process the server is.


In one word: Scalability. If you don't use session at all it means that your application is stateless which is great. In a web farm scenario you just throw another server and you are ready to tackle a new load of your site. You could also use out of process sessions (like SQLServer or StateServer) and the session will be shared between all nodes of the farm but then this state server becomes a sensible single point of failure of the entire site.

There is also another issue with sessions: because session is not thread safe if there are two parallel requests for the same session (think AJAX calls) to a controller action which writes to the session those two requests will simply queue and execute sequentially.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜