这个
PageHandlerExecutingContext
参数传递给
OnPageHandlerExecutionAsync
提供实现这一目标所需的一切。下面是一个具体的例子:
public async Task OnPageHandlerExecutionAsync(
PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
if (context.HandlerMethod?.Name == "Update")
{
// Running inside a handler method named "Update".
}
// ...
}
HandlerMethod
是非-
null
当执行处理程序方法时。它提供了这些可能感兴趣的属性:
或者,如果你想退出
处理者
级别,您可以使用自定义属性并检查其是否存在
OnPageHandlerExecutionAsync
:
public class SomePageFilterExcludeAttribute : Attribute { }
[SomePageFilterExclude]
public void OnPostUpdate() { }
public async Task OnPageHandlerExecutionAsync(
PageHandlerExecutingContext ctx, PageHandlerExecutionDelegate next)
{
var isHandlerExcluded = ctx.HandlerMethod?.MethodInfo?.
GetCustomAttributes(typeof(SomePageFilterExcludeAttribute), false).Any() == true;
// ...
}