title: Separate DbContext for Identity, User.Identity empty after login
body: <p>I've got two DBs, one for business entities and one for Identity. I'm also using external (Azure Ad) login to authenticate to Identity. All of this worked when I had it all in one DB and one DbContext. However, as soon as I split it out, the issue I run into is that after logging in, on subsequent requests <code>User.Identity.IsAuthenticated</code> is false (and thus <code>User.Identity.Name</code> is null, as well as Role/Claims data... you get the point). No errors are thrown anywhere in the external registration/login process; it's just as if my application does not know which context to look at for User.Identity information.</p>
  
  <p>Here is the body of my <code>ConfigureServices</code> in <code>Startup.cs</code>:</p>
  
  <pre><code>services.AddAuthentication(sharedOpts =&gt;
  {
      sharedOpts.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
      sharedOpts.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  })
  .AddAzureAd(opts =&gt; Configuration.Bind("AzureAd", opts))
  .AddCookie();
  
  services.AddIdentity&lt;AspNetUsers, AspNetRoles&gt;()
     .AddEntityFrameworkStores&lt;CoreUMContext&gt;()
     .AddDefaultTokenProviders();
  
  services.AddMvc();
  
  string dataConnection = Configuration["ConnectionStrings:TrackerDatabase"];
  string userConnection = Configuration["ConnectionStrings:UserDatabase"];
  Trace.TraceWarning("Connecting to connection at: " + dataConnection);
  try {
      services.AddDbContext&lt;EdgeContext&gt;(options =&gt; options.UseSqlServer(dataConnection));
      services.AddDbContext&lt;CoreUMContext&gt;(options =&gt; options.UseSqlServer(userConnection));
  }
  catch (Exception ex) {
      Trace.TraceError("Error connecting to DB: " + ex);
  }
  </code></pre>
  
  <p>I know middleware can be tricky with the order you add to the pipeline, so I've tried every combo (<code>.AddIdentity</code> before <code>.AddAuthentication</code>, adding <code>CoreUMContext</code> before the <code>EdgeContext</code>, etc.). Injecting the Identity context (<code>CoreUMContext</code>) into my controllers does not solve the issue either.</p>
  
  <p>Again, this line works</p>
  
  <pre><code>var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
  </code></pre>
  
  <p>and <code>result.Succeeded</code> returns true, so to some degree it's working, but I can't seem to find good literature on the exact path User.Identity follows to resolve itself.</p>
  
  <p>I'd greatly appreciate if anyone can shed light, as I'd really like to not have to go back to an all-in-one-db or all-in-one-context scenario as this doesn't really fit my architectural requirements.</p>
  
  <blockquote>
    <p><strong>UPDATE</strong></p>
  </blockquote>
  
  <p>It seems that the issue is Chrome not storing/sending the property cookie Identity uses to resolve which user is making the request. It works in Microsoft Edge however. This switched at some point for me yesterday and I'm still trying to deduce why (clearing cookies has not worked), but it appears the multiple contexts were not the cause of the problem.</p>