Hi I have some codes that need to run for 1 time for a request. I have a BaseController which all controllers derived from. I write my code to BaseController onActionExecuting method but it is not good because for every action execution code is running. I can prenvent it with a basic if clause but i dont want to use it like that.
What is the best place for run a code 1 time for a request. I also want to reach HttpContext where i write this code. thanks
After your comment about child actions you could test if the current action is a child action and don’t execute the code. So you could have a custom action filter:
and then decorate your base controller with this custom attribute. Similar test could be performed in the overridden OnActionExecuting method of your base controller if you prefer it instead of action attributes: