Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core - Scaffold Identity like MVC

I have created a Web Application MVC project with Individuals User Accounts authentication.

Afterwards I created a custom UserIdentity. I am trying to change the default "Register" view of Identity adding my new fields, however I only managed to scaffold new pages as Razor Pages.

My question is: Is it possible to scaffold these new views in some structure like MVC? I would not like to mix MVC with Razor Pages at all.

If this is not possible, is there any way to creating a controller that overrides the default behavior (Identity/Account/Register for example)?

like image 841
Exprove Avatar asked Nov 19 '18 03:11

Exprove


People also ask

Is ASP.NET Core identity secure?

ASP.NET Core provides many tools and libraries to secure ASP.NET Core apps such as built-in identity providers and third-party identity services such as Facebook, Twitter, and LinkedIn.

What is identity framework in ASP.NET Core?

ASP.NET Core Identity provides a framework for managing and storing user accounts in ASP.NET Core apps. Identity is added to your project when Individual User Accounts is selected as the authentication mechanism. By default, Identity makes use of an Entity Framework (EF) Core data model.

What is scaffolding in ASP.NET Core?

ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models.


2 Answers

For anyone that wants to "scaffold" identity on MVC, I recommend the following approach:

Go to the official identity ASP.net Github Repository (https://github.com/aspnet/Identity) and download it. Open the solution and search for the IdentitySample.Mvc project. Copy the necessary files to your project.

Important Note: Don't forget to change the namespace on the added files since they belong to a different project.

like image 153
Exprove Avatar answered Oct 18 '22 04:10

Exprove


No, it is not possible. The Identity team decided to switch to Razor Pages for the default UI, and now that is all there is. If you like, you can manually create controllers and views, referencing code from the scaffolded Razor Pages to create the same thing in MVC, but that is on you. There is no automatic way to do so.

like image 35
Chris Pratt Avatar answered Oct 18 '22 03:10

Chris Pratt