aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 869 forks source link

Identities aren’t stored when using an in-memory database #1961

Closed pekspro closed 5 years ago

pekspro commented 5 years ago

with

services.AddDbContext<ApplicationDbContext>(options =>
    options.UseInMemoryDatabase(Guid.NewGuid().ToString()));

Run the application and register an account. Logout and try to login with the created account. This will fail.

It looks like nothing is written in the Users-table when an account is registered.

I know there are some limitations when using an in-memory database, but shouldn’t this work? If it’s not supported I would prefer an exception than the current behavior.

blowdart commented 5 years ago

@HaoK

HaoK commented 5 years ago

I think this behavior might be by design, @ajcvickers can you confirm?

It appears that you need to use a static database name for it to work across requests:

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseInMemoryDatabase("identity"));

This works for me, but your new guid name didn't work for me either

ajcvickers commented 5 years ago

@HaoK Yep. The same database name needs to be used for saving and querying.

pekspro commented 5 years ago

😳 That so obvious! I don’t get how I could miss that. Thanks for the answer.