title: ASP.NET MVC3 creating new sessions on ajax requests
body: <p>Well, I finally had to create an account here. Been using this for years and have often found my answer here, but not this time.
  Well, I actually have found a lot of people with similar problems, but none of their solutions have helped me.</p>
  
  <p>I have started on a new MVC3 project, so it's quite simple so far. I've made a handful before, so I kinda know what I'm doing (but not quite, obviously, why else be here ;-)</p>
  
  <p>My problem is apparently a fairly common one: A request starts a new Session, even though the user already has one. </p>
  
  <p>The most frustrating part of this is, it works perfectly on my hosted service, but is broken on localhost.</p>
  
  <p>I have done a number of things to solve this:</p>
  
  <ul>
  <li>There is no underscore in my computer's name.</li>
  <li>The Session contains custom data (the error only occurs after user has logged in).</li>
  <li>I have added the following to web.config (hmpf, guess you'll have to assume the gt / lt chars):</li>
  </ul>
  
  <pre>
      httpProtocol
        customHeaders
          clear /
          add name="Access-Control-Allow-Origin" value="*" /
        /customHeaders
      /httpProtocol
  </pre>
  
  <ul>
  <li><p>and this too:</p>
  
  <pre>modules runAllManagedModulesForAllRequests="false"/</pre></li>
  <li><p>With InProc sessionstate, I have tried with 'cookieless' both true and false.</p></li>
  <li>My hosts file contains nothing about localhost. </li>
  </ul>
  
  <p>hm. Looking at this list I'm sure I've left some out. Some on purpose too, as they were hopeless (yes, even more than the above), and born from desperation.</p>
  
  <p>As mentioned this is particularly unnerving as it works on my host - could there be some configuration settings I need to tweak on the dev server (VS2010)?</p>
  
  <p>I've been working from the premise that the issue is due to cross-domain security (it thinks I'm coming from another domain).</p>
  
  <p>The fail happens on this request: </p>
  
  <pre>url: 'http://localhost:50396/moody/changeBuilding/' + elem.selectedIndex,  </pre>
  
  <p>It's part of the options array I use with the jQuery.ajax function.</p>
  
  <p>I change the domain when uploading to the host, but only the part localhost:port, everything else in the application is identical.</p>
  
  <p>I've been banging my head against this for 2 days now, and will miss my exam :-(
  I'm determined to bury this 6 feet under, though.</p>
  
  <p>I would be very grateful for any and all suggestions!</p>