# Controllers & Actions

## Feature flags in Controllers

Entire controllers, or individual actions can be annotated with the FeatureGate attribute. If the feature is off, they can't execute

```csharp
[FeatureGate(FeatureFlags.Users)]
[Route("users")]
[Controller]
public class UsersController : Controller
{
    ...
}
```

## Feature usage in Controllers

Stats are collected automatically when a feature is evaluated, but using is different than being available. To mark a controller or controller method to count as active use of a feature (for usage reporting) just add the FeatureUsage attribute

```csharp
[FeatureGate(FeatureFlags.Users)]
[FeatureUsage(FeatureFlags.Users)]
[Route("users")]
[Controller]
public class UsersController : Controller
{
    ...
}
```

{% hint style="warning" %}
The FeatureUsage attribute needs to be declared after the FeatureGate attribute, otherwise, usage will be counted even if the action isn't allowed by the FeatureGate flag, resulting in incorrect reporting
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toggly.io/feature-flags/feature-flags-in-c-.net/controllers-and-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
