MVC3 the right way to change culture for each request

I am using MVC3 and have some logic to change the culture in which everything works fine. My problem is that there are several places where this change should be made, and I'm not sure where there will be a better place for this.

Some examples show an override for each action from within such a controller:

protected override void OnActionExecuted(ActionExecutedContext filterContext) { // code to change culture } 

While the more traditional way I'm used to seeing is doing this in the Global.asax file as follows:

 protected void Application_BeginRequest(object sender, EventArgs e) { // code to change culture } 

What is the recommended place for this?

+6
source share
2 answers

global.asax is the right way to ASP.NET. It works in different environments (web forms, dynamic data, mvc).

+6
source

Application_BeginRequest excellent. If you set the culture in the stream, the entire HTTP request will be executed in that culture.

 Thread.CurrentThread.CurrentCulture = new CultureInfo(myCulture); 
+4
source

Source: https://habr.com/ru/post/909085/


All Articles