asp.net mvc where to set default culture?

2019-05-07 08:16发布

For multilingual asp.net mvc web site.

Where should i set thread's culture to default language (which is tr-TR for my case), in addition i need to save this in cookie if it does not exists. in Application_Start() or else ?

I have multiple sites(domains), so i need to change default language site specific.

 example.com must set default culture to tr-TR
 example2.com must set default culture to en-US

2条回答
ゆ 、 Hurt°
2楼-- · 2019-05-07 08:36

You can set culture in Application_AcquireRequestState:

protected void Application_AcquireRequestState(object sender, EventArgs e)
{
    // A Cookie
    string cookie = HttpContext.Current.Request.Cookies["culture"].Value;

    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(cookie);
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(cookie);
}

You can also visit this link

查看更多
淡お忘
3楼-- · 2019-05-07 08:50

Try it setting in web.config

<configuration>
    <system.web>
        <globalization uiCulture="en-GB" culture="en-GB" />
    </system.web>
</configuration>

this is a more generic way to set the culture...

查看更多
登录 后发表回答