I have a base controller in my mvc application that all controllers inherit from. the base controller inherits the abstract class Controller in the System.Web.Mvc
namespace, i need to set the culture on each controller action. there are many methods that i can override like OnActionExecuting, Initialize, ExecuteCore, BeginExecute
taking performance into consideration which one is best suited for the job? (the 4 methods above are just examples for a comprehensive list see MSDN)
We implemented a way of changing the culture based on the user's Accept-Language header but also allowed them to explicity set this themselves and we asked ourselves the same question.
We found the Initialize method the best place to set this as it is called before the other methods and before any action filters. This was important for us as we wanted the action filters to honour the intended culture.
I'm not sure if there would be any performance difference setting the culture in each of these methods. I believe they would just execute at different points in time i.e before action filters, before modelbinding & after tempdata has loaded etc.
I believe we have a helper class somewhere on our source repo that would outline how we did it. Let me know if you would like this and I'll dig it out.
Apologies, I know your question was more performance specific I just wanted to share my experience.
Update
As requested here is the helper class we have used.
To use it, just override your controller's Initialize method
The good thing about this approach is the culture will be automatically set the first time the user enters the application based on their browser settings without the user knowing.
It can also fallback to a main language so if a user requests en-US but the application only supports en-GB, it's clever enough to return en-GB as it is still an english language.
Let me know if you have any questions :)