ActionFilter for functions in razor project is not working

114 Views Asked by At

My aim is to log when and who is calling the GetAll() functions, as i remember from MVC ActionFilter, it just works that way, but when i try to implement similar filter from razor, the filter is not working? Anyone knows where i did wrong? I am referring to the documentation of this Filter methods for Razor Pages in ASP.NET Core

I have created the sample.razor page like this, it display list of records.

@page "/sample"

<BlazorAgGrid @ref="AgGrid" RowData="result.Items" TRow="SampleViewModel"
              AutoGenerateColumns="false"
              Debug="false" Options="AgGridOptions" Attributes="Attributes"
              AutoSizeColumns="true">
    <BlazorAgGridColumn HeaderName="Sample1" Field="Sample1"/>
    <BlazorAgGridColumn HeaderName="Sample2" Field="Sample2"/>
    <BlazorAgGridColumn HeaderName="Sample3" Field="Sample3"/>
    
</BlazorAgGrid>

@code
{
    private BlazorAgGrid<SampleViewModel> AgGrid;
    public Dictionary<string, object> Attributes { get; set; } = new Dictionary<string, object>()
        {
            { "style", "height: 500px" },
            { "class",  "ag-theme-balham" }
        };
    private BlazorAgGridOptions AgGridOptions = new()
        {
            RowSelection = RowSelection.Single,
            SuppressRowDeselection = true,
            EnablePagination = false,
            EnablePaginationAutoPageSize = false
        };
    private PagedList<SampleViewModel> result = new();
        result = await SampleService.GetAll();
}

here is the GetAll() function

 [SampleActionFilter]
 public async Task<PagedList<SampleViewModel>> GetAll()
 {
     return await _httpClient.GetFromJsonAsync<PagedList<SampleViewModel>>
                    ($"sample/list");
 }

here is the actionFilter i trying to make

using Microsoft.AspNetCore.Mvc.Filters;
using System.Threading.Tasks;

namespace Pages.Sample
{
    public class SampleActionFilter : ResultFilterAttribute
    {
        public SampleActionFilter()
        {
        }

        public override void OnResultExecuted(ResultExecutedContext context)
        {
            base.OnResultExecuted(context);
        }

        public override void OnResultExecuting(ResultExecutingContext context)
        {
            base.OnResultExecuting(context);
        }

        public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            return base.OnResultExecutionAsync(context, next);
        }
    }
}
0

There are 0 best solutions below