- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 Visual Studio 2017,因为在 Angular 模板中禁用了 Individual User Account
选项 我在想如何向它添加用户身份验证?我刚开始使用 VS 2017 和 .Net Core 2.1,所以我在网上搜索是否有关于如何操作的文档,但我找不到任何东西。
我看到一个答案,我只需要在命令提示符中输入 dotnet new angular --auth Individual
但我无法使用它,因为我使用的是 Window 8.1 和命令适用于 .Net Core 3 和 VS 2019
我已经阅读了所有关于这个主题的谷歌搜索结果,但没有任何帮助。我什至使用其他搜索引擎希望得到更好的结果,但一无所获。
最佳答案
将 Dotnet 核心 3.0 与 Entityframework 核心 3.0 和 Identityserver4 结合使用,您可以拥有一个以 Angular 作为前端、Asp.net Core 3.0 作为后端的应用程序。查看此链接
Authentication and authorization for SPAs
首先你需要从here下载dotnet core 3.0 sdk .
然后打开命令提示符并使用
dotnet new angular -o <output_directory_name> -au Individual
这将为您创建项目。
现在在 Visual Studio 中转到“工具”>“选项”>“环境”>“预览功能”并检查
Use Previews of the .NET Core SDK (Requires Restart)
并重新启动 visual studio。
之后打开项目目录中的 .csProj 文件并点击保存。这将要求您保存在 visual studio 中打开项目时刚刚创建的解决方案文件。
将 .sln 文件保存在与 .csproj 相同的目录中,然后清理解决方案并重建解决方案。
您将拥有以 Asp.net Core 作为后端的 Angular 应用程序,并为您提供开箱即用的身份验证和授权。
这是您完成所有步骤后应用程序的示例屏幕截图
请注意,在项目目录中,您将拥有一个 app.db 文件,并且在 startup.cs 的 ConfigureServices 方法中,您将看到
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
模板默认使用 Sqlite,您可以通过安装 Microsoft.EntityFrameworkCore.SqlServer NuGet 包并在 startup.cs 文件中更改它来将其更改为 Sql server
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
到
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
并确保更新 appsettings.json 文件中的连接字符串。
关于angular - 如何将用户身份验证添加到 .NET Core 2.1 Angular 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57668568/
我是一名优秀的程序员,十分优秀!