using AsmResolver.PE.DotNet.Cil; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using static asg_form.Controllers.AssignmentController; namespace asg_form.Controllers { public class BlackDB { public int id { get; set; } public string user_name { get; set; } //..... } [ApiController] public class BlackController : ControllerBase { [Route("api/v1/blackTable")] [HttpGet] public async Task> blackAdd ([FromQuery] string userName) { if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin")||!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { return Ok(new error_mb { code = 401, message = "无权访问" }); } TestDbContext sub = new TestDbContext(); return Ok(new { code = 200, message = "" }); } } }