I love it when I learn something new from a question. Thanks to @MikeBrind's comment and the following links (Learn Page Filters and the MS doc on Page Filters) I can answer this question and update my code.
I also have a base class that sets a global query filter on the DbContext so each user's data is filtered from each other. I have a common method (called PageLoadAsync) that I have to remember to add to each page's OnGet/OnPost methods. Now with an override of the executing methods I can add the following and not have to add the method in each subclass.
public async override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
await PageLoadAsync();
await base.OnPageHandlerExecutionAsync(context, next);
}
If you want to restrict it to just the OnGet method you can do something like the following:
public override void OnPageHandlerExecuting(PageHandlerSelectedContext context)
{
if(context.HandlerMethod.MethodInfo.Name == nameof(OnGet))
{
// code placed here will only execute if the OnGet() method has been selected
}
}
base.OnGet
doesn't work you?