欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net core 授權(quán)詳解

 更新時(shí)間:2020年01月20日 11:42:38   作者:wall-ee  
在本篇文章里小編給大家整理了關(guān)于asp.net core 授權(quán)的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。

IAuthorizeDate接口代表了授權(quán)系統(tǒng)的源頭:

public interface IAuthorizeData
{
  string Policy { get; set; }
  string Roles { get; set; }
  string AuthenticationSchemes { get; set; }
}

接口中定義的三個(gè)屬性分別代表了三種授權(quán)類(lèi)型:

1、基于角色的授權(quán):

[Authorize(Roles = "Admin")] // 多個(gè)Role可以使用,分割
public class SampleDataController : Controller
{
  ...
}

2、基于scheme的授權(quán):

[Authorize(AuthenticationSchemes = "Cookies")] // 多個(gè)Scheme可以使用,分割
public class SampleDataController : Controller
{
  ...
}

3、基于策略的授權(quán):

[Authorize(Policy = "EmployeeOnly")]
public class SampleDataController : Controller
{
  
}

基于策略的授權(quán)是授權(quán)的核心,使用這種授權(quán)策略時(shí),首先要定義策略:

public void ConfigureServices(IServiceCollection services)
{
  services.AddMvc();

  services.AddAuthorization(options =>
  {
    options.AddPolicy("EmployeeOnly", policy => policy.RequireClaim("EmployeeNumber"));
  });
}

授權(quán)策略本質(zhì)上就是對(duì)claims的一系列斷言。

而基于角色和基于scheme的授權(quán)都是一種語(yǔ)法糖,最終會(huì)轉(zhuǎn)換為策略授權(quán)。

以上就是關(guān)于asp.net core 授權(quán)的知識(shí)點(diǎn)內(nèi)容,如果大家有任何疑問(wèn)可以聯(lián)系腳本之家小編。

相關(guān)文章

最新評(píng)論