首页 > 编程语言 >User Registration with ASP.NET Core Identity

User Registration with ASP.NET Core Identity

时间:2023-07-13 14:45:10浏览次数:38  
标签:Core ASP User model password method Identity user

User Registration with ASP.NET Core Identity

So basically, we have all the input fields from our model in this view. Of course, clicking the Create button will direct us to the POST Register method with the UserRegistrationModel populated.

Now, let’s install the AutoMapper library, so we could map the UserRegistrationModel to the User class:

 

As you can see, the action is async now because the UserManager’s helper methods are async as well. Inside the action, we check for the model validity and if it is invalid, we just return the same view with the invalid model.

If that check passes, we map the registration model to the user.

Additionally, we use the CreateAsync method to register the user. But this method does more for us. It hashes a password, executes an additional user checks and returns a result.

If the result is successful, we just attach the default role to the user, again with the UserManager’s help, and redirect the user to the Index page.

But if the registration fails, we loop through all the errors and add them to the ModelState.

 

创建的用户保存到了AspNetUsers用户表,并且添加了默认的role,会在AspNetUserRoles添加用户和角色的关系。

 

Identity Options

As you could see in the testing example, our user registration process requires a password to fulfill certain rules. These rules can be found and adjusted in the IdentityOptions settings.

Right now, the password requires at least 6 characters, upper and lower case letters, etc.

Let’s play around a bit with these values.

 

标签:Core,ASP,User,model,password,method,Identity,user
From: https://www.cnblogs.com/chucklu/p/17550420.html

相关文章

  • asp.net core identity tables
      SELECT*FROMdbo.AspNetUsers--hasdataSELECT*FROMdbo.AspNetUserLoginsSELECT*FROMdbo.AspNetUserRoles--hasdataSELECT*FROMdbo.AspNetUserTokensSELECT*FROMdbo.AspNetUserClaimsSELECT*FROMdbo.AspNetRoles--hasdataSELECT*FROMdbo.......
  • Asp.net core中的配置提供程序和读取
    ASP.NETCore中的应用程序配置是使用一个或多个配置提供程序执行的。配置提供程序使用各种配置源从键值对读取配置数据:设置文件,例如appsettings.json环境变量AzureKeyVaultAzure应用程序配置命令行参数已安装或已创建的自定义提供程序目录文件内存中的.NET对象......
  • ASP.NET Core 6框架揭秘实例演示[40]:基于角色的授权
    原文:https://www.cnblogs.com/artech/p/inside-asp-net-core-6-40.htmlASP.NET应用并没有对如何定义授权策略做硬性规定,所以我们完全根据用户具有的任意特性(如性别、年龄、学历、所在地区、宗教信仰、政治面貌等)来判断其是否具有获取目标资源或者执行目标操作的权限,但是针对角色......
  • net core-异步,同步理解
    并发: 一个车间只有一台机器,所有的工人都需要完成相同的工作,谁先抢到这个机器谁先工作,其余人需要等待。并行: 一个车间有4台机器,有4个工人,四个工人分别使用四台机器,同时执行任务,不用等待其它工人任务执行完毕。单线程: 当有三件事要处理,乙需要在甲之后处理,同时丙需要在乙之......
  • [LeetCode] 2542. Maximum Subsequence Score
    Youaregiventwo 0-indexed integerarrays nums1 and nums2 ofequallength n andapositiveinteger k.Youmustchoosea subsequence ofindicesfrom nums1 oflength k.Forchosenindices i0, i1,..., ik-1,your score isdefinedas:Thes......
  • .net 温故知新【12】:Asp.Net Core WebAPI 中的Rest风格
    RPCRPC(RemoteProcedureCall),远程过程调用),这种RPC形式的API组织形态是类和方法的形式。所以API的请求往往是一个动词用来标识接口的意思,比如https://xxxx/GetStudent?id=1和https://xxxx/AddStudent这种风格,并且往往没有规范需要我们去查看接口定义文档。HTTP方法基本只用GE......
  • net-core(DynamicExpresso.Core)
    ==============================(Install-PackageDynamicExpresso.Core)======================================varwhereExpression=$"m.{queryField}==\"{queryValue}\"";stringwhereExpression="customer.Age>18&&......
  • Microsoft.AspNetCore.Http.Abstractions 2.20 is deprecated
     您想要升级Microsoft.AspNetCore.Http.Abstractions包,您需要注意以下几点:Microsoft.AspNetCore.Http.Abstractions包在ASP.NETCore2.2版本后已经被标记为过时,因为它已经被包含在Microsoft.AspNetCore.App框架引用中12。因此,您不需要单独引用这个包,只需要在项目文件中......
  • ASP.NET CORE 框架揭秘读书笔记系列——命令行程序的创建(一)
    一、dotnet--info查看本机开发环境dotnet--info 会显示本机安装的SDK版本、运行时环境、运行时版本二、利用命令行创建.NET项目我们不仅可以利用脚手架模版创建各种类型的应用项目,还可以为项目添加各种组件和配置。换句话说IDE能完成的各项工作全部都可以通过脚手架命令行......
  • 在WinServer 2022 Core 上安装SCVMM2022和SqlServer2022
    在WindowsServer2022Core上安装SystemCenterVirtualMachineManager(VMM)2022管理服务器和SqlServer2022CU5系统环境如下:OS:windowsserver2022CoreDataCenterDB:SqlServer2022withCU5ADK: Windows11版本22H2的ADK: https://learn.microsoft.com/zh-cn/wi......