Core Identity Razor Pages or directly use User/Role/SignIn Managers

JORGE MALDONADO BARRERA 211 Reputation points
2021-08-28T23:14:32.487+00:00

Hi,

I have been studying Core Identity to implement security in a new ASP.NET Core 5 project and I see that I can use the Identity Razor Pages already implemented. However, this would result in 2 development approaches in the same project: MVC and Razor Pages.

Also, I have the choice to directly use SignInManager, UserManager and RoleManager classes to implement the desired functionality following the MVC pattern. In this way, all of my project would be a one-pattern-project.

Is there a reason to avoid mixing MVC and Razor Pages in a project?
Is it a good/bad practice?
From a pro perspective, how does mixing MVC and Razor approaches look?

Respectfully,
Jorge Maldonado

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,684 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,646 Reputation points Microsoft Vendor
    2021-08-29T02:39:41.697+00:00

    Hi @Luis Maldonado,

    Is there a reason to avoid mixing MVC and Razor Pages in a project?
    Is it a good/bad practice?
    From a pro perspective, how does mixing MVC and Razor approaches look?

    As we all known, a Razor Page has similarities with the view component of ASP.NET MVC. Just like MVC, it has almost the same functionality as well as syntax. The main difference between MVC and Razor pages is the fact that the controller code and the model are likewise included inside the Razor Page.

    Razor Pages work well when your content is structured and is ideal for the login page or contact us page due to its simplicity. MVC is for complex databases of users or product descriptive lists. Heavy apps constructed using MVC can get cluttered by too many programmers handling codes as some may miss out on good programming practices.

    Razor Pages requires you to put code related to the specific page. To enable better control split codes, it saves you from managing huge coding in the controller. Optionally you can create external classes for the logic to keep the controllers clean.

    By using the ASP.NET Core Identity, it includes a default UI as a Razor library that enables you to quickly add users to an application, without having to build all the UI yourself. If you want to add customer user data to identity, it is easier to achieve.

    If you don't want to use the Scaffold Identity and prevent use Razor page in your application, you can remove the following code in the Startup.cs file:
    services.AddRazorPages(); and endpoints.MapRazorPages();

    And you have to create all the relates page to manage user, roles and more.

    In my opinion, I might choose to use the mixing MVC and Razor approaches, because Scaffold Identity can generate these pages, and all the Identity relates page was in the Identity/Pages folder, it is easier to find them and the relates model.

    Finally, whether using the one-pattern or mix-pattern, it should depend on your application and choice.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.