Creating Custom Action Filters
The possible uses for action filters are as varied as the actions to which they can be applied. Some possible uses for action filters include the following: Logging in order to track user interactions. "Anti-image-leeching" to prevent images from being loaded in pages that are not on your site. Web crawler filtering to change application behavior based on the browser user agent. Localization to set the locale. Dynamic actions to inject an action into a controller. Implementing a Custom Action Filter An action filter is implemented as an attribute class that inherits from ActionFilterAttribute. ActionFilterAttribute is an abstract class that has four virtual methods that you can override: OnActionExecuting, OnActionExecuted, OnResultExecuting, and OnResultExecuted. To implement an action filter, you must override at least one of these methods. The ASP.NET MVC framework will call the OnActionExecuting method of your action filter before it calls any action method that is marked...