更改.net asp mvc 4文化信息,适用范围广

时间:2013-05-31 02:25:23

标签: asp.net-mvc globalization cultureinfo

我有一个完整的应用程序,它使用Web应用程序,数据库和一些业务逻辑层。问题是它们中的每一个都配置为使用系统文化。我需要将文化固定为所有文化中的不变量或标准文化。我已经尝试在web.config中添加全球化标签,但我仍然遇到问题,它似乎无法正常工作。

我还在我的布局页面中添加了“globalize.js”脚本,因此脚本可以像系统的其余部分一样工作,但它也不起作用。

1 个答案:

答案 0 :(得分:5)

尝试将此代码添加到global.asax

using System.Globalization;
    using System.Threading;
    protected void Application_BeginRequest(object sender, EventArgs e)
    {

        string lang = Request.RequestContext.RouteData.Values["culture"].ToString();
        //CultureInfo culture = CultureInfo.InvariantCulture;//if need invariant
        CultureInfo culture = CultureInfo.GetCultureInfo(lang);

        Thread.CurrentThread.CurrentUICulture = culture;
        Thread.CurrentThread.CurrentCulture = culture;
    }

适合我

相关问题