Other related issues are found during my migration.

Unable to Change Identity Table Names

https://stackoverflow.com/questions/46118930/unable-to-change-asp-identity-table-names-asp-net-core-2

I faced the same issue as the above post. To fix it, I need to derive my database context with all the parameters specified:

public sealed class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int, IdentityUserClaim<int>, IdentityUserRole<int>, IdentityUserLogin<int>, ApplicationRoleClaim, IdentityUserToken<int>>

.Net Core 2.0 Web API OpenIddict Authorization: redirecting to login instead of returning JSON data

https://stackoverflow.com/questions/45784814/net-core-2-0-web-api-openiddict-authorization-redirecting-to-index-instead-of

Changed the following code in Startup.cs

// Register the OAuth2 validation handler as required by oidc
             services.AddAuthentication().AddOAuthValidation();

To:

// Register the OAuth2 validation handler as required by oidc
             services.AddAuthentication(options =>
             {
                 options.DefaultAuthenticateScheme = OAuthValidationDefaults.AuthenticationScheme;
             }).AddOAuthValidation();

The property 'Roles' is not a navigation property of entity type 'ApplicationUser'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names. or

The property 'Users' is not a navigation property of entity type 'ApplicationRole'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names.

Based on the suggestions from Microsoft Docs, I added the navigation propertied back as suggested but now I am getting these errors. In EntityFramework Core 2.0, Fluent API has not implemented many to many relationships. The example given in the office documentation will define role and user relationship as one to many and one extra field can be added to your database model. So eventually I have decided to use ApplicationUserRole to do the work.

Define a custom class first:

public class ApplicationUserRole : IdentityUserRole<int>
     {
         public virtual ApplicationRole Role { get; set; }

        public virtual ApplicationUser User { get; set; }
     }

In Application Role, remove the Users navigation property added previously with the following:

#region  asp.net core 2.0 support
         /// <summary>
         /// Navigation property for the claims this role possesses.
         /// </summary>
         public virtual ICollection<ApplicationRoleClaim> Claims { get; set; }

        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
         #endregion

In Application User, remove the Roles navigation property added previously with the following:

#region  asp.net core 2.0 support
         /// <summary>
         /// Navigation property for the claims this user possesses.
         /// </summary>
         public virtual ICollection<IdentityUserClaim<int>> Claims { get; set; }
         /// <summary>
         /// Navigation property for this users login accounts.6
         /// </summary>
         public virtual ICollection<IdentityUserLogin<int>> Logins { get; set; }

        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
         #endregion

In all my projects, I then changed to use UserRoles to find all the users in one role or vice versa. This is the only way I found it work to migrate.

After more than one day’s work, I have now finally migrated my asp.net core 1.1 web application to asp.net core 2.0 with OIDC server integrated as well.


info Last modified by Raymond at 9 months ago copyright This page is subject to Site terms.

More from Kontext

Entity Framework Core Code-First - Generate Covering Index with Columns Included

local_offer entity-framework local_offer asp.net core local_offer Azure local_offer C#

visibility 41
thumb_up 0
access_time 2 months ago

In SQL Server or some other relational databases, it is a very common requirement to create covering index with columns included in index pages beside the index key columns. With Entity Framework Core, you can also easily generate covering indexes using purely C# code. Scenario For ...

open_in_new ASP.NET Core

local_offer asp.net core local_offer asp.net core 3

visibility 25
thumb_up 0
access_time 3 months ago

Sign-in with social accounts like Google, Microsoft, Twitter and Facebook accounts are very commonly used in websites to allow website users to logon easily without registering an separate account. Issue summary During the implementation of Kontext Google sign-in function, I encoun...

open_in_new ASP.NET Core

Modern Web Application - Azure Blob Storage for Uploaded Files

local_offer Azure local_offer asp.net core local_offer dotnetcore

visibility 523
thumb_up 0
access_time 5 months ago

With cloud platforms like Azure, we can totally separate user content storage from web application storage to decouple components from each other and to make the application easy to scale and deploy. This article provides detailed information with code snippets about how to use Azure server-less product Blob Storage and App Service to enable horizontally scalable web application for users to upload files (BLOBs).

open_in_new Azure

local_offer asp.net core local_offer gulp

visibility 308
thumb_up 0
access_time 2 years ago

Background If you have been working on ASP.NET projects in the past years, you probably have heard or used quite a few client library management frameworks/tools. For example, Bower, npm, Gulp, Grunt, Webpack, Yarn, Parcel, Libman, etc. Before SPA became popular, the default ASP.NET (or A...

open_in_new ASP.NET Core

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward