This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

Migrating from ASP.NET Core 1.x to ASP.NET Core 2.0 – Issues Continued

736 views 0 comments last modified about 12 months ago Raymond

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.

Related pages

Set AttachDbFilename as Relative Path in .NET Core

68 views   0 comments last modified about 2 months ago

.NET Framework, you can use |DataDirectory| to configure connection string when connecting to SQL Server database file via attach mode: AttachDbFilename=|DataDirectory|\dbname.mdf In .NET Core, you cannot directly set SQL Server Express connec...

View detail

Set AttachDbFilename as Relative Path in .NET Core

68 views   0 comments last modified about 2 months ago

.NET Framework, you can use |DataDirectory| to configure connection string when connecting to SQL Server database file via attach mode: AttachDbFilename=|DataDirectory|\dbname.mdf In .NET Core, you cannot directly set SQL Server Express connec...

View detail

Instantiate a Service in ConfigureServices Method in .NET Core

21 views   0 comments last modified about 2 months ago

.NET Core is built in with dependency injection. Usually method ConfigureServices in Startup class is used to register services in the container. The signature of the method looks like the following: public void ConfigureServices(IServiceC...

View detail

Instantiate a Service in ConfigureServices Method in .NET Core

21 views   0 comments last modified about 2 months ago

.NET Core is built in with dependency injection. Usually method ConfigureServices in Startup class is used to register services in the container. The signature of the method looks like the following: public void ConfigureServices(IServiceC...

View detail

ASP.NET Core 2.1 Error - 'Cyrillic' is not a supported encoding name

86 views   0 comments last modified about 2 months ago

After upgrading to ASP.NET Core 2.1 (.NET Core SDK 2.1.301), you may encounter the following error about encoding: System.ArgumentException &nbsp;&nbsp; HResult=0x80070057 &nbsp;&nbsp; Message='Cyrillic' is not a supported encoding name. For information on defining a custo...

View detail

SQLite in .NET Core with Entity Framework Core

41 views   0 comments last modified about 2 months ago

SQLite is a self-contained and embedded SQL database engine. In .NET Core, Entity Framework Core provides APIs to work with SQLite. This page provides sample code to create a SQLite database using package Microsoft.EntityFrameworkCore.Sqlite . Create sample project ...

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.