Subscribed unsubscribe Subscribe Subscribe

clock-up-blog (en)

tech memo

(ASP.NET MVC) Forcing all exception messages to be in English

(If you prefer Japanese than English, you can see Japanese article.)

Error messages often provide us hints to live, but they also confuse us when they are not in English.
We hope ENGLISH error messages.

The solution

All we have to do is specify the culture information to CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture.

Global.asax.cs

....
using System.Globalization;
....
namespace WebApplication1
{
  public class MvcApplication : System.Web.HttpApplication
  {
    protected void Application_Start()
    {
      CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Add
      CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US"); // Add
....

OK, that's all.
f:id:kobake:20160819015521p:plain

The other solution?

We can also specify the culture information in Web.config.

Web.config

....
<system.web>
  ....
  <globalization
    requestEncoding="utf-8"
    responseEncoding="utf-8"
    fileEncoding="utf-8"
    culture="en-US"
    uiCulture="en-US" />
</system.web>
....

It seems good? Actually it's not enough. See the images below.
f:id:kobake:20160819015703p:plain

There are English messages mixed with some Japanese words.

I recommend not Web.config but CultureInfo in order to get comfortable DEBUG environment.