Putting a common logic in every action of controll

2019-08-15 02:33发布

问题:

I am developing a mvc app where i have lot of common functionality in every controller action. My question is that where should i put a common initilization logic in every action of controller

回答1:

You have two choice.

  • Action Filter

  • create basecontroller and inherit all controller from basecontroller

see this link for your reference



回答2:

If you don't want to create an action filter (see here) and place the attribute in each action, you can create a controller that inherits from the base mvc controller and override the OnActionExecuting or OnActionExecuted method to provide common behavior for all actions in a controller. Hope it helps