Store does not implement IUserRoleStore ASP.NET Core Identity

In Startup.cs, I was missing AddRoles so services.AddDefaultIdentity<PortalUser>() .AddEntityFrameworkStores<ApplicationDbContext>(); should be services.AddDefaultIdentity<PortalUser>() .AddRoles<IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>(); Note: The order is critical. AddRoles must come before AddEntityFrameworkStores

Using Windows Domain accounts AND application-managed accounts

The simplest approach is to have 2 different presentation Projects only for Authentication/Authorization. This has the advantage of leaning on existing framework and standard configuration. From there, you decide to either create an AD user for every internet user, or create a DB/Internet user for every AD user. Creating an Identity user for each AD …

Read more

What is the difference in the use of UserStore and UserManager in ASP.NET Identity?

Things are quite complicated there and could have been easier. UserManger is the … manager. It does not really interact with the storage, the database. That’s what the UserStore does. In fact UserManager has a constructor which needs a UserStore. Why would you have to different object to manage users? Well, the main reason is …

Read more

“Trust relationship between … and the primary domain failed” in MVC5 Authentication

So, based on my EDIT, I’ve modified my _Layout.cshtml so that instead of having @if(User.IsInRole(“Admin”)) {…} I have @if(User.Identity.IsAuthenticated && User.IsInRole(“Admin”)) {…} which seems to solve the problem. I believe the problem was that ASP .NET Identity uses an empty WindowsIdentity when no user is authenticated and when I try to check for the User.IsInRole, …

Read more

How to Construct IdentityResult With Success == true

Would the static IdentityResult.Success property work? http://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.identityresult.success(v=vs.108).aspx Edit: To add some more detail, it seems what you want to do is get your mocked CreateAsync to return an IdentityResult where Suceeded is true. For that I would just return IdentityResult.Success from your mock. There’s shouldn’t be a need to mock the IdentityResult itself. Example: How …

Read more

What is the use of Normalized Email & UserName in .NET core IdentityUser Model?

By my understanding, both fields are there for performance reasons. It’s sort of explained in the following thread Normalization on UserName and Email causes slow performance and are used to validate the case insensitive uniqueness of the UserName and Email fields. They are persisted in the database in order be able to create index on …

Read more

How do I use ASP.NET Identity 2.0 to allow a user to impersonate another user?

I’ve found a solution to this problem. Basically I add claim with admin username, if this claim exists, I know that impersonation is happening. When admin wants to stop impersonation, system retrieves original username for the claims, deletes old impersonated-cookie and creates a new cookie for the admin: [AuthenticateAdmin] // <- make sure this endpoint …

Read more