Home > Mobile >  How to create ASP.NET Core web application for existing Azure database with identity tables
How to create ASP.NET Core web application for existing Azure database with identity tables

Time:02-24

I have an existing Xamarin mobile application hooked to a backend that is a .NET Framework 4.7.1 web application hosted in Azure. It only contains the logic and links to push notifications hubs in azure, and also does the new user registration and login authentication for the mobile app.

I researched and realized it would not be a good idea (or cannot even) upgrade the .NET Framework 4.7.1 existing Web API to a .NET Core 3.1 / Net 6 Web API.

I am thinking to create a new .NET Core 3.1/ Net 6 project that will ALSO hook up to the existing database and keep adding functionality for the mobile in this new project, such as a password reset feature, more modern and easy to maintain. Both web apis will be operational (so I can avoid updating the mobile azure notfication packages and hub, which would result if i modified the original backend project)

The multi-part questions:

Is this approach a good approach? If not, what is the alternative?

The existing database has Microsoft Identity tables, so when I create the new NET Core 3.1 / Net 6 project, do I select Authentication with Microsoft Identity as an option? When scaffolding the azure existing db connection string, will this hook the authentication logic automatically for me into the new project with the existing tables (even though the users tables has a slightly modified custom name and added some columns in previous project when created)?

CodePudding user response:

Posting as an answer (because too long for a comment)

First of all, you can upgrade from .NET 4.7 to NETCore, I have done that recently (4.7.2 to NetCore5). Provided that you are not using a library or package that has not been yet ported to NetCore. e.g. My project was targeting EF6, i had to first migrate the entire project to EFCore5. Then change the code in DbContext, recreate the DB Migrations, fix some of the Queries (especially the GroupBy queries) etc. Then finally I could upgrade to NetCore5.

Regarding the 2nd part of your question, I don't think it is bad idea to have separate API for some of your functionality, but personally I would avoid if upgrading the existing project is feasible. (Maybe start fresh and port of the rest of the code gradually?)

A thing to also keep in mind, is that maybe AspnetCore Identity schema is different to Aspnet Identity schema (just a thought, not sure)

I have recently migrated a Custom Users and authentication system to AspnetCore Identity, I used IdentityServer4 alongside AspnetCore Identity. I am not sure how you are authenticating the users etc. but I was already using IdentityServer4, when I scaffold it with the AspnetCore Identity UI/Authentication it created the UIs/Business logic for authentication (I had to tweak it a bit, and had to customise some of it to keep working with our Mobile Apps)

Also, I had to manually migrate our users from Custom Users table to the new Identity.Users table. I created a Utility App (Console Application) which read the users from existing Users table and created them under the Microsoft --> Identity tables.

I think it took me about a month to upgrade from

1 - EF6 --> EfCore

2 - Net471 --> NetCore5

3 - Custom Users --> AspnetCore Identity

  • Related