title: asp.net mvc4 cross domain session lost
body: <p>I'm creating a new web application using ASP.net MVC4 </p>
  
  <p>our application web site runs on 2 doamin names www.domain1.com &amp; www.domain2.com</p>
  
  <p>since there are lots of common controllers/view i implemented Areas that are bound to the domain</p>
  
  <pre><code>public override string AreaName
          {
              get
              {
                  return "NS1";
              }
          }
          public override void RegisterArea(AreaRegistrationContext context)
          {
              context.MapRoute(
              "NS1_default", "{controller}/{action}",
              new { controller = "Home", action = "Index" },
              new { hostname = new areaRedirect("www.domain1.com") }
          ).DataTokens["UseNamespaceFallback"] = true;
          }
  </code></pre>
  
  <p>And for domain2</p>
  
  <pre><code>public override void RegisterArea(AreaRegistrationContext context)
      {
          context.MapRoute(
          "NS2_default", "{controller}/{action}",
          new { controller = "Home", action = "Index" },
          new { hostname = new areaRedirect("www.domain1.com") }
          ).DataTokens["UseNamespaceFallback"] = true;
      }
  </code></pre>
  
  <p>This works fine and does everything i need BUT..</p>
  
  <p>when i switch from one area to the other i loose my logged in session.</p>
  
  <p>is there a way to stay logged in? the account controller is common to both areas. </p>
  
  <p>so basically same app, same server just that my namespace happens to be a domain name</p>
  
  <p>instead of seeing www.somedomain/domain1/action we get www.domain1/action</p>
  
  <p>Thanks for your time </p>