Comments (3)
Right, it says
Your user and role entities must inherit from MongoIdentityUser and MongoIdentityRole
but it doesn't call out that MongoIdentityUser doesn't inherit from IdentityUser, nor does it call out that the partial needs to be updated. These should be called out in the README.
That's why I converted the MVC sample that was in the MSFT repo
Samples are nice, but is it your intention that we copy your sample as a starting point? Maybe that works fine for MVC, but that leaves out people who are developing Razor Pages or Blazor apps. Because of that, the README should call out the bare minimum to get started, regardless of project type.
from aspnetcore.identity.mongodbcore.
I figured it out, though I don't like the solution...
First IdentityUser
is used in all the default Identity templates, so, by default, _LoginPartial.cshtml
is looking for a binding to UserManager<IdentityUser>
and no matching service could be found.
Looking at the inheritance chain, I found that
MongoIdentityUser
inherits fromIdentityUser<Guid>
IdentityUser
inherits fromIdentityUser<string>
So that explains why this error keeps showing up: MongoIdentityUser
doesn't actually inherit from IdentityUser
.
I don't know how you can clearly communicate this through code, so at the very least, the documentation should show how to convert a default Identity template to use this provider instead.
from aspnetcore.identity.mongodbcore.
Hello thanks for your message. Not sure what the issue is here.
the documentation should show how to convert a default Identity template to use this provider instead.
<= That's why I converted the MVC sample that was in the MSFT repo :
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/tree/b3db4eb39fcd2d1f0df59ffbb6933dc53f794476/sample/MongoIdentitySample.Mvc.
Where the partial is indeed different:
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/blob/master/sample/MongoIdentitySample.Mvc/Views/Shared/_LoginPartial.cshtml
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
UserManager<IdentityUser>
cannot work in this package.
As mentioned in the docs:
Your user and role entities must inherit from
MongoIdentityUser<TKey>
andMongoIdentityRole<TKey>
in a way similar to theIdentityUser<TKey>
and theIdentityRole<TKey>
in Microsoft.AspNetCore.Identity, where TKey is the type of the primary key of your document.
If you really want string primary keys:
public class ApplicationUser: MongoIdentityUser<string>
{
public MyUser () : base()
{
}
public MyUser (string userName, string email) : base(userName, email)
{
}
}
with matching role:
public class ApplicationRole : MongoIdentityRole<string>
{
public ApplicationRole() : base()
{
}
public ApplicationRole(string roleName) : base(roleName)
{
}
}
then:
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddMongoDbStores<ApplicationUser, ApplicationRole, string>
(
"mongodb://localhost:27017",
"MongoDbTests"
)
.AddDefaultTokenProviders();
As highlighted in:
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore#user-and-role-entities
If you feel like the docs are not clear enough please feel free to raise a PR. I understand your frustration but unfortunately I cannot satisfy everyone. I advise you to copy the sample and use it as a boiler plate for your project to avoid issues.
I hope this makes sense.
from aspnetcore.identity.mongodbcore.
Related Issues (20)
- Unable to post Register using sample project. HOT 7
- Issues with the 3.1.0 version HOT 3
- Perfomance comparison to SQL databases
- Update Readme HOT 2
- Use of IMongoClient instead of MongoClient HOT 1
- Does this work with .net5? HOT 10
- Comparison with another implementation HOT 2
- Injecting SignInManager through DI causing issues when trying to resolve HOT 4
- Update MongoDb driver to 2.13 HOT 2
- Update (your own) MongoDbGenericRepository nuget to latest 1.4.7 HOT 2
- CollectionNames While Using Generics HOT 1
- Stores use a static IMongoRepository
- This work on .net6 HOT 4
- IDictionary<string, string> Properties missing on MongoClaim HOT 1
- explanation services.AddIdentity multi roles HOT 1
- Does this work with .net7 preview? HOT 1
- Is there a recommended approach to use with worker & console apps?
- How to set document in [users] collection save as camelCase
- Publish next NuGet version
- Login does not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetcore.identity.mongodbcore.