验证码在服务器端生成
介绍 (Introduction)
The latest preview for .NET Core 3 (preview-6) has introduced the functionality to add authentication and authorization in a server-side Blazor application. In this article, we will learn how to implement authentication and authorization using Google in a server-side Blazor application. You can refer to my previous article Understanding Server-side Blazor to get in-depth knowledge on server-side Blazor.
.NET Core 3的最新预览版(预览版6)引入了在服务器端Blazor应用程序中添加身份验证和授权的功能。 在本文中,我们将学习如何在服务器端Blazor应用程序中使用Google实施身份验证和授权。 您可以参考我以前的文章“ 了解服务器端Blazor”,以获取有关服务器端Blazor的深入知识。
先决条件 (Prerequisites)
Install the latest .NET Core 3.0 Preview SDK from here.
从此处安装最新的.NET Core 3.0 Preview SDK。
Install the latest preview of Visual Studio 2019 from here.
从此处安装Visual Studio 2019的最新预览版。
Install ASP.NET Core Blazor Language Services extension from here.
从此处安装ASP.NET Core Blazor语言服务扩展。
源代码 (Source Code)
Get the source code from GitHub
从GitHub获取源代码
创建服务器端Blazor应用程序 (Create Server Side Blazor Application)
To create a server-side Blazor app, open Visual Studio 2019 and follow the steps mentioned below.
若要创建服务器端Blazor应用,请打开Visual Studio 2019并按照以下步骤操作。
- Click on “Create a new project”. 点击“创建一个新项目”。
- Select “ASP.NET Core Web Application” from available project types. Click on Next. 从可用的项目类型中选择“ ASP.NET Core Web应用程序”。 单击下一步。
A new “Configure your new project” screen will open. Put the name of the project as
BlazorGoogleAuth
and click Create.一个新的“配置新项目”屏幕将打开。 将项目名称命名为
BlazorGoogleAuth
,然后单击“创建”。- In the next screen, select “.NET Core” and “ASP.NET Core 3.0” from dropdowns on the top left. 在下一个屏幕中,从左上方的下拉菜单中选择“ .NET Core”和“ ASP.NET Core 3.0”。
- Select “Blazor (server-side)” from the list of available templates. 从可用模板列表中选择“ Blazor(服务器端)”。
Click on Change Authentication button, a “Change Authentication” dialog box will open. Select “Individual User Account” and click OK. Click on
Create
button to create the application.单击更改身份验证按钮,将打开“更改身份验证”对话框。 选择“个人用户帐户”,然后单击“确定”。 单击
Create
按钮创建应用程序。
These steps are shown in the GIF image below.
这些步骤显示在下面的GIF图像中。