MVC is an abstraction of ASP.NET, and therefore their “hooks” really depend on what level you want to introduce your logic into. An action filter allows you to connect to specific MVC events:
OnActionExecuting - This method is called before the controller action is performed.OnActionExecuted - This method is called after the controller action is completed.OnResultExecuting - this method is called before the result of the controller action is executed.OnResultExecuted - this method is called after the result of the controller action.
While the HttpModule allows you to connect to ASP.NET (through which MVC is created) certain events:
BeginRequest - Request started. If you need to do something at the beginning of the request (for example, display advertising banners at the top of each page), synchronize this event.AuthenticateRequest . If you want to connect your own authentication scheme (for example, search for a user in the database to verify the password), create a module that synchronizes this event and authenticates the user in such a way that you want.AuthorizeRequest - this event is used internally to implement authorization mechanisms (for example, to store access control lists (ACLs) in the database, and not in the file system). Although you can redefine this event, there are not many good reasons for this.PreRequestHandlerExecute - This event occurs before the HTTP handler executes.PostRequestHandlerExecute - This event occurs after the execution of the HTTP handler.EndRequest - Request completed. You might want to create a debugging module that collects information for the entire request and then writes information to the page.
So it really depends on when you need to connect to your event and what events you need.
armen.shimoon
source share