By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .

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 5 months ago * This page is subject to Site terms.

More from Kontext

local_offer asp.net core local_offer gulp

visibility 231
thumb_up 0
access_time 13 months 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 View open_in_new ASP.NET Core

local_offer asp.net core 2 local_offer asp.net core local_offer dotnetcore local_offer open-banking

visibility 216
thumb_up 0
access_time 2 years ago

I’ve just started an asp.net core 2.2 based implementation for Australia Consumer Data Standards (published by Data 61). Opening Banking initiative will follow these standards. The purpose is to help you to get familiar with these standards, especially the APIs that need to be implemented. ...

open_in_new View open_in_new ASP.NET Core

local_offer asp.net core 2 local_offer .net core

visibility 1893
thumb_up 0
access_time 2 years ago

In .NET Core 2.x, Windows Forms or WPF are not implemented since they are based on GDI+ and DirectX respectively in Windows. In .NET Core 3.0, there is plan to add Desktop Packs which includes UWP. WPF and Windows Forms. However, they will still be Windows-only. In .NET Core applications, you may...

open_in_new View open_in_new ASP.NET Core

local_offer asp.net core local_offer identity core 2

visibility 15409
thumb_up 0
access_time 3 years ago

The identity system in ASP.NET has evolved over time. If you are using ASP.NET Core, you probably found User property is an instance of ClaimsPrincipal in Controller or Razor views. Thus to retrieve the information, you need to utilize the claims.

open_in_new View open_in_new ASP.NET Core

info About author

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward
Kontext Column

Kontext Column

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

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us