在 .NET Core 3.0 中使用登录

Using Login in .NET Core 3.0

在 MVC 5 中,我使用它来实现登录、注销以及 ExternalLogin 和 Callback 方法。现在我正在尝试遵循微软指南,但它们没有出现在模板中,我很困惑。当我到达它加载的 account/login 页面时,我还没有看到登录或帐户控制器。这里发生了什么?我似乎找不到这方面的信息。

编辑:澄清一下,我希望构建一个控制器来处理登录,因为我需要实现额外的处理逻辑。 Razor Pages 对我不起作用。我在哪里可以找到有关如何实现此目的的代码示例?

从 ASP.NET Core 2.1 开始,用于登录和注册的 UI 包含在 Microsoft.AspNetCore.Identity.UI library.

您可以按照本指南将文件包含在您的项目中:Scaffold Identity in ASP.NET Core projects

该指南针对各种场景有更详细的说明,但对于空项目,来自Visual Studio:

  • From Solution Explorer, right-click on the project > Add > New Scaffolded Item.
  • From the left pane of the Add Scaffold dialog, select Identity > ADD.
  • In the ADD Identity dialog, select the options you want.
    • Select your existing layout page, or your layout file will be overwritten with incorrect markup. For example ~/Pages/Shared/_Layout.cshtml for Razor Pages ~/Views/Shared/_Layout.cshtml for MVC projects
    • Select the + button to create a new Data context class.
  • Select ADD.

或从 CLI:

# install the scaffolder tool
dotnet tool install -g dotnet-aspnet-codegenerator

# add the code generation NuGet package to your project
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet restore

dotnet aspnet-codegenerator identity --useDefaultUI