首页 > 编程语言 >Authentication With ASP.NET Core Identity

Authentication With ASP.NET Core Identity

时间:2023-07-13 14:55:49浏览次数:39  
标签:Core ASP Authentication going NET Identity

Authentication With ASP.NET Core Identity、

Preparing the Authentication Environment in our Project

The first thing, we are going to do is disable unauthorized users to access the Employees action. To do that, we have to add the [Authorize] attribute on top of that action:

[Authorize]
public async Task<IActionResult> Employees()
{
    var employees = await _context.Employees.ToListAsync();
    return View(employees);
}

Additionally, we have to add authentication middleware to the ASP.NET Core’s pipeline right above the app.UseAuthorization() expression:

app.UseAuthentication();

If we run our application now and click on the Employees link, we are going to get a 404 not found response:

 

We get this because, by default, ASP.NET Core Identity tries to redirect an unauthorized user to the /Account/Login action, which doesn’t exist at the moment. Additionally, you can see a ReturnUrl query string that provides a path to the required action before the user was redirected to the Login page. We are going to deal with it later in this post.

 

Now, we are going to do a couple of things to fix this 404 error.

 

标签:Core,ASP,Authentication,going,NET,Identity
From: https://www.cnblogs.com/chucklu/p/17550450.html

相关文章

  • User Registration with ASP.NET Core Identity
    UserRegistrationwithASP.NETCoreIdentitySobasically,wehavealltheinputfieldsfromourmodelinthisview.Ofcourse,clickingtheCreatebuttonwilldirectustothePOSTRegistermethodwiththe UserRegistrationModel populated.Now,let’sinst......
  • 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。因此,您不需要单独引用这个包,只需要在项目文件中......
  • Redis 命令行中报错 (error) NOAUTH Authentication required
    本文来源:redis客户端连接错误NOAUTHAuthenticationrequired_Redis_脚本之家redis客户端连接成功,但是操作报异常——(error)NOAUTHAuthenticationrequired错误的含义是说你没有认证,说明没有使用密码连接查看密码:进入redis的安装目录,查看redis.config文件,viredis.conf......