Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an IPageFilter on razor page with no model

Is there a way to apply an IPageFilter on a razor page which does not have a model?

The page is a simple get request.

@page
@{
    @functions{

        public void OnGet()
        {
        }
    }
}

Just want to know If it's possible to add a simple i.e. Authorize attribute (or any IPageFilter attributes) in the above page. As the attributes work on following page when there exist a child class of PageModel.

@{
    @functions
    {
        [Authorize]
        public class TestModel : PageModel
        {
            public void OnGet()
            {
            }
        }
    }
}
like image 488
eadam Avatar asked Jan 26 '26 12:01

eadam


1 Answers

You could use a page application model convention to add one. There’s an AddFilter convention extension that accepts a func

like image 86
RickAndMSFT Avatar answered Jan 29 '26 10:01

RickAndMSFT