How to Set Locale Setting in a C# Web Application Globally

To be able to set your web application global setting, you need to set it in global.asax file. And to make it more dynamic it's better to set the locale setting string in web.config.

//web.config
<configuration>
  <appSettings>
  <add key="Locale" value="en-PH" />
  </appSettings>
<configuration>

//global.asax
public void Application_BeginRequest(object sender, EventArgs e)
{
  Thread.CurrentThread.CurrentCulture = new CultureInfo(ConfigurationManager.AppSettings["Locale"]);
  Thread.CurrentThread.CurrentUICulture = new CultureInfo(ConfigurationManager.AppSettings["Locale"]);
}

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source
Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.