I am using MVC3, and have some logic for changing the culture which all works fine. My issue, is that there seems a few places where this change should be made, and I am unsure where would be the best place to do it.
Some examples show an override on each action, from within a controller like this:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
// code to change culture
}
Whereas a more traditional way that I am used to seeing is doing it in the Global.asax file as follows:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// code to change culture
}
What is the recommended place to do this?
global.asax is the ASP.NET correct way of doing this. It works across frameworks (webforms, dynamic data,mvc).
Application_BeginRequest
is fine. If you set the culture on the thread there, the whole HTTP Request will be executed in that culture.
Thread.CurrentThread.CurrentCulture = new CultureInfo(myCulture);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With