Skip to content

Commit 572769b

Browse files
authored
Add documentation for FeatureGateAttribute usage on Razor pages. (#169)
1 parent 50e9ca2 commit 572769b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ services.AddMvc(o =>
224224

225225
The code above adds an MVC filter named `SomeMvcFilter`. This filter is only triggered within the MVC pipeline if the feature it specifies, "FeatureV", is enabled.
226226

227+
### Razor Pages
228+
MVC Razor pages can require that a given feature, or one of any list of features, be enabled in order to execute. This can be done by using a `FeatureGateAttribute`, which can be found in the `Microsoft.FeatureManagement.Mvc` namespace.
229+
230+
``` C#
231+
[FeatureGate(MyFeatureFlags.FeatureU)]
232+
public class IndexModel : PageModel
233+
{
234+
public void OnGet()
235+
{
236+
}
237+
}
238+
```
239+
240+
The code above sets up a Razor page to require the "FeatureU" to be enabled. If the feature is not enabled, the page will generate an HTTP 404 (NotFound) result.
241+
242+
When used on Razor pages, the `FeatureGateAttribute` must be placed on the page handler type. It cannot be placed on individual handler methods.
243+
227244
### Application building
228245

229246
The feature management library can be used to add application branches and middleware that execute conditionally based on feature state.

0 commit comments

Comments
 (0)