title: Why is in memory data persisted across multiple browser sessions in my MVC prototype?
body: <p>I've got a basic MVC application - generated from the MVC application template.  I've created a basic controller which contains the usual Index, Details, Edit and Create methods; I've got a couple of classes one to hold my object called Person:</p>
  
  <pre><code>public class Person
  {
      public int Id { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>And another to mock up a fake DAL. It doesn't persist the data to file or a database, it's just a quick mock-up for the purpose of this prototype:</p>
  
  <pre><code>public class PersonData
  {
      /* Fake out our initial repository */
      static List&lt;Person&gt; People = new List&lt;Person&gt;()
      {
          new Person() { Id=1, FirstName="John", LastName="Doe", Description="King of the world" },
          new Person() { Id=2, FirstName="Jane", LastName="Doe", Description="Chief whip cracker" }
      };
  
      /* Set up the indexing system */
      private static int GetNextId()
      {
          return People.OrderByDescending(i =&gt; i.Id).First().Id + 1;
      }
  
      public static IEnumerable&lt;Person&gt; GetPeople()
      {
          return People;
      }
  
      public static Person GetPerson(int id)
      {
          if (id &gt; People.OrderByDescending(i =&gt; i.Id).First().Id)
              throw new ArgumentOutOfRangeException();
  
          return People.Where(i =&gt; i.Id.Equals(id)).SingleOrDefault();
      }
  
      public static void Save(Person data)
      {
          /* Either remove the old one or assign a new ID */
          if (data.Id != 0)
              People.Remove(People.Where(i =&gt; i.Id.Equals(data.Id)).SingleOrDefault());
          else
              data.Id = GetNextId();
  
          People.Add(data);
      }
  }
  </code></pre>
  
  <p>There's nothing particularly interesting about the controller either, here's the excerpt of the Edit functionality:</p>
  
  <pre><code>    // GET: /Person/Edit/5
      public ActionResult Edit(int id)
      {
          Person person = PersonData.GetPerson(id);
          return View(person);
      }
  
      //
      // POST: /Person/Edit/5
      [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Edit(Person person)
      {
          try
          {
              PersonData.Save(person);
              return RedirectToAction("Details", person);
          }
          catch
          {
              return View(person);
          }
      }
  </code></pre>
  
  <p>Everything functions, but I've noticed a couple of curious anomalies that I can't explain.  First up, if I make a change to a person in my edit form and save it, everything is reflected in the details page just fine.  Then I cue up another browser instance - Opera/Chrome/Whatever and enter the details page for that person.  I was expecting to see that in the second browser, I would see the data previous to my changes because the PersonData is only loaded in memory and it's not persisted - however, I see the changes that were made in browser 1 in the second browser.</p>
  
  <p>I chalked this up to being because I'm running in Visual Studio's Development Server and assumed that I was just accessing the same session.  To prove the hypothesis I added the Session ID to the details page expecting to see the same session ID, but I was wrong.  Each session has a different ID.</p>
  
  <p>Further to this - the session ID changes with every page refresh in both browsers, and they're always different from each other.</p>
  
  <p>I don't understand why this is and wonder if someone could explain:</p>
  
  <ul>
  <li>Why is the data from my DAL mock persisting across both browsers when they're both on different sessions?</li>
  <li>Why is the session id not being maintained across page refreshes?</li>
  </ul>
  
  <p>Thanks in advance</p>