2021-10-21 06:47:17 +08:00
---
title: "MVC1001: Filters cannot be applied to page handler methods"
description: "Learn about analysis rule MVC1001: Filters cannot be applied to page handler methods"
author: pranavkm
monikerRange: '>= aspnetcore-3.1'
2024-06-18 04:11:09 +08:00
ms.author: wpickett
2021-10-21 06:47:17 +08:00
ms.date: 10/21/2021
uid: diagnostics/mvc1001
---
# MVC1001: Filters cannot be applied to page handler methods
| | Value |
|-|-|
| **Rule ID** |MVC1001|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
An attribute implementing < xref:Microsoft.AspNetCore.Mvc.Filters.IFilterMetadata > was applied to a Razor Page handler method.
### Rule description
2022-09-02 08:49:58 +08:00
Razor Page handler methods are selected after MVC filter execution has started, and consequently cannot contribute filters to execute. Applying a filter to a Razor Page handler is unsupported and always incorrect.
2021-10-21 06:47:17 +08:00
2021-10-26 01:51:19 +08:00
```csharp
public class IndexModel : PageModel
{
[MyFilter]
public IActionResult OnGet() => Page();
}
```
2021-10-21 06:47:17 +08:00
## How to fix violations
2021-10-26 01:51:19 +08:00
Remove the filter from the handler and apply it to the page model. If a filter has to be applied to a specific handler, consider using multiple Razor Pages.
```csharp
[MyFilter]
public class IndexModel : PageModel
{
public IActionResult OnGet() => Page();
}
```
2021-10-21 06:47:17 +08:00
## When to suppress warnings
Don't suppress warnings from this rule.