Skip to content

[Execute]

IntelliTect.Coalesce.DataAnnotations.ExecuteAttribute

Controls various aspects of Custom Methods, including role-based permissions, HTTP behavior, and more.

For other security controls, see Security Attributes.

Example Usage

c#
public class Person
{
    public int PersonId { get; set; }
    
    [Coalesce, Execute(Roles = "Payroll,HR")]
    public void GiveRaise(int centsPerHour) {
        ...
    }

    ...
}

Properties

public string Roles { get; set; }

A comma-separated list of roles which are allowed to execute the method.

public SecurityPermissionLevels PermissionLevel { get; set; } = SecurityPermissionLevels.AllowAuthorized;

The level of access to allow for the action for the method.

Enum values are:

  • SecurityPermissionLevels.AllowAll Allow all users to perform the action for the attribute, including users who are not authenticated at all.
  • SecurityPermissionLevels.AllowAuthorized Allow only users who are members of the roles specified on the attribute to perform the action. If no roles are specified on the attribute, then all authenticated users are allowed (no anonymous access).
  • SecurityPermissionLevels.DenyAll Deny the action to all users, regardless of authentication status or authorization level. If DenyAll is used, no API endpoint for the action will be generated.

public bool AutoClear { get; set; }

If true, the method's arguments will be cleared after a successful invocation on admin pages.

public bool? ValidateAttributes { get; set; }

If non-null, overrides the value of CoalesceOptions.ValidateAttributesForMethods when determining whether to perform automatic server-side validation of the method's parameters.

If validation is performed, the method's parameters will be validated by the server and the method invocation prevented if errors are found.

public HttpMethod HttpMethod { get; set; } = HttpMethod.Post;

The HTTP method to use on the generated API Controller.

Enum values are:

  • HttpMethod.Post Use the POST method.
  • HttpMethod.Get Use the GET method.
  • HttpMethod.Put Use the PUT method.
  • HttpMethod.Delete Use the DELETE method.
  • HttpMethod.Patch Use the PATCH method.

public string? VaryByProperty { get; set; }

For HTTP GET model instance methods, if VaryByProperty is set to the name of a property on the parent model class, ETag headers based on the value of this property will be used to implement caching. If the client provides a matching If-None-Match Header with the request, the method will not be invoked and HTTP Status `304 Not Modified`` will be returned.

Additionally, if the VaryByProperty is set to a client-exposed property, the value of the property will be included in the query string when performing API calls to invoke the method. If the query string value matches the current value on the model, a long-term Cache-Control header will be set on the response, allowing the client to avoid making future invocations to the same method while the value of the VaryByProperty remains the same.

public Type? DataSource { get; set; }

Specifies that the targeted model instance method should load the instance it is called on from the specified data source when invoked from an API endpoint. If not defined, the model's default data source is used.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.