gpt4 book ai didi

c# - OnAuthorizationAsync 中的取消 token

转载 作者:行者123 更新时间:2023-12-03 08:48:51 24 4
gpt4 key购买 nike

我有以下代码:

public class AuthorizeRolesAttribute : TypeFilterAttribute
{
public AuthorizeRolesAttribute() : base(typeof(AuthorizeRolesFilter))
{

}

public class AuthorizeRolesFilter : IAsyncAuthorizationFilter
{
public virtual async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{

}
}
}

我想使用取消 token ,所以我尝试像这样覆盖它:

public async override Task OnAuthorizationAsync(AuthorizationFilterContext context, CancellationToken ct)
{
}

但我不断收到此错误:

No suitable method found to override

最佳答案

只需从 HttpContext 获取您的 CancellationToken .

public Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var cancellationToken = context.HttpContext.RequestAborted;
...
}

关于c# - OnAuthorizationAsync 中的取消 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60169340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com