首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过dotnet将所有身份文件搭建到ASP.NET Core2.1MVC项目中?

如何通过dotnet将所有身份文件搭建到ASP.NET Core2.1MVC项目中?
EN

Stack Overflow用户
提问于 2018-09-07 13:41:00
回答 3查看 7.5K关注 0票数 15

在题为https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity的MSDN文章中,有一组专门针对“创建完整标识用户界面源”的说明(而不是使用剃刀类库的身份识别)。

本节从以下几个方面开始:

若要维护对标识UI的完全控制,请运行标识支架并选择覆盖所有文件。

没有可以在shell中运行的命令来构建所有这些文件,因此我假设“覆盖所有文件”是Visual中的UI控件。

如果我们查看dotnet aspnet-codegenerator identity -h的输出,就不会看到生成所有文件的任何选项。

代码语言:javascript
复制
Usage: aspnet-codegenerator [arguments] [options]

Arguments:
  generator  Name of the generator. Check available generators below.

Options:
  -p|--project             Path to .csproj file in the project.
  -n|--nuget-package-dir   
  -c|--configuration       Configuration for the project (Possible values: Debug/ Release)
  -tfm|--target-framework  Target Framework to use. (Short folder name of the tfm. eg. net46)
  -b|--build-base-path     
  --no-build               

Selected Code Generator: identity

Generator Options:
  --dbContext|-dc      : Name of the DbContext to use, or generate (if it does not exist).
  --files|-fi          : List of semicolon separated files to scaffold. Use the --list-files option to see the available options.
  --listFiles|-lf      : Lists the files that can be scaffolded by using the '--files' option.
  --userClass|-u       : Name of the User class to generate.
  --useSqLite|-sqlite  : Flag to specify if DbContext should use SQLite instead of SQL Server.
  --force|-f           : Use this option to overwrite existing files.
  --useDefaultUI|-udui : Use this option to setup identity and to use Default UI.
  --layout|-l          : Specify a custom layout file to use.
  --generateLayout|-gl : Use this option to generate a new _Layout.cshtml

鉴于所有这些,dotnet命令行脚手架工具的用户如何生成身份生成器中的所有文件?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-01-31 22:16:28

如果省略了--files--useDefaultUI标志,它将生成所有文件。

代码语言:javascript
复制
$ dotnet aspnet-codegenerator identity

根据文档

如果您在没有指定--files标志或--useDefaultUI标志的情况下运行标识支架,那么将在项目中创建所有可用的标识UI页面。

资料来源:

https://github.com/aspnet/Docs/pull/8752

票数 16
EN

Stack Overflow用户

发布于 2018-09-07 13:41:00

如前所述,目前没有生成所有标识文件的命令行选项。

谢天谢地,可以同时使用--files--listFiles选项来实现这一目标。

步骤1:列出可以被脚手架处理的文件

代码语言:javascript
复制
$ dotnet aspnet-codegenerator identity --listFiles
Building project ...
Finding the generator 'identity'...
Running the generator 'identity'...
File List:
Account.AccessDenied
Account.ConfirmEmail
Account.ExternalLogin
Account.ForgotPassword
Account.ForgotPasswordConfirmation
Account.Lockout
Account.Login
Account.LoginWith2fa
Account.LoginWithRecoveryCode
Account.Logout
Account.Manage._Layout
Account.Manage._ManageNav
Account.Manage._StatusMessage
Account.Manage.ChangePassword
Account.Manage.DeletePersonalData
Account.Manage.Disable2fa
Account.Manage.DownloadPersonalData
Account.Manage.EnableAuthenticator
Account.Manage.ExternalLogins
Account.Manage.GenerateRecoveryCodes
Account.Manage.Index
Account.Manage.PersonalData
Account.Manage.ResetAuthenticator
Account.Manage.SetPassword
Account.Manage.TwoFactorAuthentication
Account.Register
Account.ResetPassword
Account.ResetPasswordConfirmation

我们需要在“文件列表:”之后的所有行。

步骤2:将这些名称组合成以分号分隔的字符串。

代码语言:javascript
复制
Account.AccessDenied;Account.ConfirmEmail;Account.ExternalLogin;Account.ForgotPassword;Account.ForgotPasswordConfirmation;Account.Lockout;Account.Login;Account.LoginWith2fa;Account.LoginWithRecoveryCode;Account.Logout;Account.Manage._Layout;Account.Manage._ManageNav;Account.Manage._StatusMessage;Account.Manage.ChangePassword;Account.Manage.DeletePersonalData;Account.Manage.Disable2fa;Account.Manage.DownloadPersonalData;Account.Manage.EnableAuthenticator;Account.Manage.ExternalLogins;Account.Manage.GenerateRecoveryCodes;Account.Manage.Index;Account.Manage.PersonalData;Account.Manage.ResetAuthenticator;Account.Manage.SetPassword;Account.Manage.TwoFactorAuthentication;Account.Register;Account.ResetPassword;Account.ResetPasswordConfirmation

步骤3:再次运行生成器,这一次给选项--files我们刚刚创建的字符串

我们不能忘记用引号包围,或者我们的shell可能试图以命令的形式执行这些文件名(因为;是命令结束符)。

代码语言:javascript
复制
$ dotnet aspnet-codegenerator identity --files="Account.AccessDenied;Account.ConfirmEmail;Account.ExternalLogin;Account.ForgotPassword;Account.ForgotPasswordConfirmation;Account.Lockout;Account.Login;Account.LoginWith2fa;Account.LoginWithRecoveryCode;Account.Logout;Account.Manage._Layout;Account.Manage._ManageNav;Account.Manage._StatusMessage;Account.Manage.ChangePassword;Account.Manage.DeletePersonalData;Account.Manage.Disable2fa;Account.Manage.DownloadPersonalData;Account.Manage.EnableAuthenticator;Account.Manage.ExternalLogins;Account.Manage.GenerateRecoveryCodes;Account.Manage.Index;Account.Manage.PersonalData;Account.Manage.ResetAuthenticator;Account.Manage.SetPassword;Account.Manage.TwoFactorAuthentication;Account.Register;Account.ResetPassword;Account.ResetPasswordConfirmation"

假设成功执行,我们现在直接将所有标识代码(后端代码、UI等)直接放在源代码树中。

参考文献:

https://github.com/aspnet/Docs/issues/8443

https://github.com/aspnet/Scaffolding/issues/872

票数 13
EN

Stack Overflow用户

发布于 2022-03-03 02:02:20

我尝试过这种方法,它成功了(在asp.net核心6.0上),但是它与根本没有文件值并没有太大的不同。不管怎么说,我觉得有人会觉得这很有用

代码语言:javascript
复制
dotnet aspnet-codegenerator identity -dc MyApp.Data.ApplicationDbContext --files "$(dotnet aspnet-codegenerator identity -dc MyApp.Data.ApplicationDbContext --listFiles | grep "Account.*" | tr '\n' ';')"

基本上,您将接受生成文件的命令,然后将可能的文件列表(它们都以'Account.',因此是grep)开始,并将该输出中的所有新行转换为分号。

出于某种原因,我认为listFiles将是一个稍微具体到我的应用程序列表,但它不是。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52223806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档