2024年5月17日 星期五

自訂權限驗證機制

// 使用 filter
[Route("api/[controller]")]
[ApiController]
[Authorize]
[TypeFilter(typeof(CustomAsyncAuthorizationFilter))]
public class Controller1 : ControllerBase

// 定義 filter
public sealed class CustomAsyncAuthorizationFilter : IAsyncAuthorizationFilter
{
    public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
    {
        bool isAuthorized = await CheckUserAuthorizationAsync(context);
        if (!isAuthorized) context.Result = new ForbidResult();
    }
    private async Task<bool> CheckUserAuthorizationAsync(AuthorizationFilterContext context)
    {
       // do something and return bool
    }

input 連結 datalist 用程式控制彈出選項

範例: nextTick(() => document.querySelector('input').showPicker());  ※僅支援現代瀏覽器