简体   繁体   English

ASP.Net Core 2.1 中的身份< - 自定义 AccountController

[英]Identity in ASP.Net Core 2.1< - Customize AccountController

I have installed ASP.NET Core 2.1 but even though I have created a new ASP.NET Core Web Application using ASP.NET Core 2.1 with Individual User AccountsStore user accounts in-app I can't find the AccountController or Views.我已经安装了ASP.NET Core 2.1但即使我使用ASP.NET Core 2.1创建了一个新的ASP.NET Core Web ApplicationIndividual User AccountsStore user accounts in-app我也找不到 AccountController 或视图。

I can still register and login without a problem but I can't find the code for it, it were present in 2.0.我仍然可以毫无问题地注册和登录,但我找不到它的代码,它存在于 2.0.0 中。

在此处输入图片说明

ASP.NET Core 2.1 introduced new feature called Razor class libraries that lets you build views and pages as part of reusable library. ASP.NET Core 2.1 引入了称为 Razor 类库的新功能,可让您将视图和页面构建为可重用库的一部分。 ASP.NET Core Identity was moved to such RCL. ASP.NET Core Identity 已移至此类 RCL。 You can override it in your project:您可以在您的项目中覆盖它:

  1. From Solution Explorer , right-click on the project > Add > New Scaffolded Item .解决方案资源管理器中,右键单击项目 >添加>新建脚手架项
  2. From the left pane of the Add Scaffold dialog, select Identity > ADD .Add Scaffold对话框的左窗格中,选择Identity > ADD
  3. In the ADD Identity dialog, choose files you wish to override.在“添加标识”对话框中,选择要覆盖的文件。
    1. Select layout if necessary必要时选择布局
    2. Select or create Data context class .选择或创建数据上下文类
  4. Hit ADD .点击添加

For more information visit documentation .有关更多信息, 请访问文档

One of the changes in 2.1 was Razor Class Libraries and the default identity lives in one of these in the individual auth templates. 2.1中的更改之一是 Razor 类库,默认身份位于单个身份验证模板中的其中一个中。 If you would like to have the code in your app so you can customise it, you can scaffold it out with Visual Studio, or with the global scaffolder tool.如果您希望在您的应用程序中包含代码以便您可以对其进行自定义,您可以使用 Visual Studio 或全局脚手架工具将其搭建起来。 See this guide on how to do both.请参阅本指南以了解如何执行这两项操作。

我的解决方案是用.net core 2.0创建项目,然后将框架更新到2.1,并将所有依赖更新到最新版本

Turns out ASP.NET Core Identity is now available as a prebuilt package called Microsoft.AspNetCore.Identity.UI .事实证明, ASP.NET Core Identity现在可以作为名为Microsoft.AspNetCore.Identity.UI的预构建包使用。

You can read more about it here:你可以在这里读更多关于它的内容:

https://blogs.msdn.microsoft.com/webdev/2018/03/02/aspnetcore-2-1-identity-ui/ https://blogs.msdn.microsoft.com/webdev/2018/03/02/aspnetcore-2-1-identity-ui/

Since ASP.NET Core 2.1 theidentity UI is shipped as a library .ASP.NET Core 2.1身份 UI 作为库提供

But you can override the views and controllers by placing them at the right locations (eg View/Account/Login.cshtml).但是您可以通过将它们放置在正确的位置(例如 View/Account/Login.cshtml)来覆盖视图和控制器。

As far as I am aware, the AccountController code has been moved to Razor pages (and their code behinds) and works best using defaults so to customise the code you can Scaffold (ie create the files in the right place) from a brand new Net Core 2.1 project by right-clicking the Project in Visual Studio 2017 and seleting Add => New Scaffolded Item => Identity which opens a Select Dialog.据我所知,AccountController 代码已移至 Razor 页面(及其背后的代码),并且使用默认值效果最佳,因此可以从全新的网络自定义您可以搭建脚手架的代码(即在正确的位置创建文件) Core 2.1 项目,右键单击 Visual Studio 2017 中的项目并选择 Add => New Scaffolded Item => Identity 这将打开一个选择对话框。 Choose desired pages and there you go.选择所需的页面,然后就可以了。 Just change the pages you want and copy to same place in an Identity enabled project as these new pages automatically override the defaults.只需更改您想要的页面并复制到启用身份的项目中的相同位置,因为这些新页面会自动覆盖默认值。 This is the new way to customize authentication/authorization using Identity not sure whether many consider this significant progress!这是使用 Identity 自定义身份验证/授权的新方法,不确定是否很多人认为这是重大进展!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM