asp.net-mvcshared-state

What is Shared State in an ASP.NET MVC Application?


In a recent Stackoverflow podcast (#59), Jeff Atwood mentions that Stackoverflow has some "shared state." I understand the general idea of shared state, but what exactly is shared state in the context of an ASP.NET MVC application, like Stackoverflow?

Specifically, I'd like to know the following:

  1. What does it look like? How do you spot it in the wilderness?
  2. What limitations does it bring to a system?
  3. How do you get rid of it?
  4. If it's so bad, why would someone include it in their design?

Solution

  • After listening to the latest Stackoverflow podcast, I have figured out what Jeff was referring to as shared state.

    1. What does it look like? How do you spot it in the wilderness?

    Jeff was referring to the use of the Session variable in ASP.NET MVC.

    2. What limitations does it bring to a system?

    If not configured properly, use of the session variable can tie a user to a specific web server. If a user hops between different web servers between requests, then data in the Session variable will not be available.

    3. How do you get rid of it?

    You can get rid of shared state by persisting the Session variable to a database that is accessible from all web servers. ASP.NET provides an option to persist the Session variable to the database free of charge, but for some reason Jeff was reluctant to use this feature. He mentioned that he loves deleting code, however he decided to roll his own mechanism to persist session state to the database.

    4. If it's so bad, why would someone include it in their design?

    Because it's right there when you're coding and it's easy.

    alt text http://www.codeproject.com/KB/mobile/DeepCast/easy-button.jpg