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

asp.net core 授權詳解

 更新時間:2020年01月20日 11:42:38   作者:wall-ee  
在本篇文章里小編給大家整理了關于asp.net core 授權的相關知識點內容,需要的朋友們學習下。

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

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

接口中定義的三個屬性分別代表了三種授權類型:

1、基于角色的授權:

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

2、基于scheme的授權:

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

3、基于策略的授權:

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

基于策略的授權是授權的核心,使用這種授權策略時,首先要定義策略:

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

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

授權策略本質上就是對claims的一系列斷言。

而基于角色和基于scheme的授權都是一種語法糖,最終會轉換為策略授權。

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

相關文章

最新評論