Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ActionFilterAttribute Class

Represents the base class for filter attributes.


Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method, Inherited = true, 
	AllowMultiple = false)]
public abstract class ActionFilterAttribute : FilterAttribute, 
	IActionFilter, IResultFilter

The ActionFilterAttribute type exposes the following members.

Protected methodActionFilterAttributeInitializes a new instance of the ActionFilterAttribute class.

Public propertyAllowMultipleGets or sets a value that indicates whether more than one instance of the filter attribute can be specified. (Inherited from FilterAttribute.)
Public propertyOrderGets or sets the order in which the action filters are executed. (Inherited from FilterAttribute.)
Public propertyTypeId (Inherited from Attribute.)

Public methodEquals (Inherited from Attribute.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Attribute.)
Public methodGetType (Inherited from Object.)
Public methodIsDefaultAttribute (Inherited from Attribute.)
Public methodMatch (Inherited from Attribute.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodOnActionExecutedCalled by the ASP.NET MVC framework after the action method executes.
Public methodOnActionExecutingCalled by the ASP.NET MVC framework before the action method executes.
Public methodOnResultExecutedCalled by the ASP.NET MVC framework after the action result executes.
Public methodOnResultExecutingCalled by the ASP.NET MVC framework before the action result executes.
Public methodToString (Inherited from Object.)

Typically, you create an action or response filter by creating an attribute class that inherits from the abstract ActionFilterAttribute class. Some built-in action filters, such as AuthorizeAttribute and HandleErrorAttribute, inherit from the FilterAttribute class. Other action filters, such as OutputCacheAttribute, inherit from the abstract ActionFilterAttribute class, which enables the action filter to run either before or after the action method runs.

You can use filter attributes to mark any action method or controller. If the attribute marks a controller, the filter applies to all action methods in that controller.

The following example shows how to create a simple action filter that logs trace messages before and after an action method is called.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2018 Microsoft