示例
新建PersonsAlwaysRunResultFilter.cs
using Microsoft.AspNetCore.Mvc.Filters;
namespace CRUDExample.Filters.ResultFilters
{
public class PersonsAlwaysRunResultFilter : IAsyncAlwaysRunResultFilter
{
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
await next();
}
}
}
去掉缓存设置,造成Authorization short-circuiting
[HttpGet]
[Route("[action]/{personId}")] //persons/edit/1
//[TypeFilter(typeof(TokenResultFilter))]
public async Task<IActionResult> Edit(Guid personId)
应用PersonsAlwaysRunResultFilter
[HttpPost]
[Route("[action]/{personId}")] //persons/edit/1
[TypeFilter(typeof(TokenAuthorizationFilter))]
[TypeFilter(typeof(PersonsAlwaysRunResultFilter))]
public async Task<IActionResult> Edit(PersonUpdateRequest personUpdateRequest)
程序运行后点击Edit,可以看到即使Authorization没有通过,PersonsAlwaysRunResultFilter中的方法OnResultExecutionAsync被执行了。
Gitee获取源码:
https://gitee.com/huang_jianhua0101/asp.-net-core-8.git
标签:IAlwaysRunResultFilter,Task,TypeFilter,personId,PersonsAlwaysRunResultFilter,typ From: https://blog.csdn.net/KevinHuang2088/article/details/139451521