正确的CurrentCulture默认为en-US在ASP.net [英] CurrentCulture incorrectly defaulting to en-US in ASP.net

查看:774
本文介绍了正确的CurrentCulture默认为en-US在ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从迁移IIS 6约100 ASP.net网站在Windows Sever的2003到IIS 7的Windows 2008年我刚刚注意到,使用之类的东西DateTime.Parse code的各个部分已经开始踢了错误字符串未被识别为有效的DateTime。我跟踪下来的事实,网站的的CurrentCulture被默认为EN-US所以我的英国用户在一个意想不到的格式输入日期。

I have just migrated around 100 ASP.net sites from IIS 6 on Windows Sever 2003 to IIS 7 on Windows 2008. I've just noticed that various pieces of code that use things like DateTime.Parse have started kicking up errors "String was not recognized as a valid DateTime". I've tracked this down to the fact that the CurrentCulture of the sites is defaulting to 'en-US' and so my UK users are inputting dates in an unexpected format.

问题是,他们在哪里得到的en-US的?从顶部开始,如果我期待在控制面板>区域和语言都设置为英语(英国)。网站的任一web.configs不具有与所述;全球化>段或把它当作设置<全球化文化=自动的UICulture =自动/取代。在IIS7 - .NET全球化所有的网站都有其文化设置为固定语言(不变地)

Question is, where are they getting en-US from? Starting from the top, if I look in 'Control Panel > Region and Language' everything is set to English (United Kingdom). The web.configs of the sites either don't have a <globalization> section or have it set as <globalization culture="auto" uiCulture="auto" />. In 'IIS7 - .Net Globalization' all of the sites have their culture set to 'Invariant Language (Invariant Country)'.

我不能在任何地方找到的设置文化EN-US......但事情是。

I can't find anywhere that's settings the culture to 'en-US'... but something is.

Thread.CurrentThread.CurrentCulture.Name is outputting 'en-US'
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol is outputting '$'

我可以通过加入LT解决问题;全球化文化=EN-GB的UICulture =EN-GB/&GT;每web.config中,但我真的不希望有手工编辑约100 web.configs!我wan't它从服务器操作系统设置,并将其设置为EN-GB。

I can fix the issue by adding <globalization culture="en-GB" uiCulture="en-GB" /> to every web.config BUT I really don't want to have to hand edit about 100 web.configs! I wan't it to inherit the culture from the server OS settings, which are set to en-GB.

我缺少的东西吗?

推荐答案

这是另类的地方,你可以搜索:

These are alternative places where you could search:

我不能在任何地方找到的设置文化EN-US......但事情是。

I can't find anywhere that's settings the culture to 'en-US'... but something is.

Thread.CurrentThread.CurrentCulture.Name正在输出EN-US
  Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol正在输出$

Thread.CurrentThread.CurrentCulture.Name is outputting 'en-US' Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol is outputting '$'

试着寻找 InitializeCulture 的方法,这种方法被覆盖在ASP.Net网页设置的文化,如:

Try looking for the InitializeCulture method, this method is overridden in ASP.Net pages to set the Culture like:

protected override void InitializeCulture()
{
    var hidden = this.Request.Form["hidden"];
    var culture = this.Request.Form[hidden];
    if (!string.IsNullOrWhiteSpace(culture))
    {
        this.Culture = culture;
        this.UICulture = culture;
    }

    base.InitializeCulture();
}

尝试查找以下程序集属性:

Try to look for the following assembly attributes:

    [assembly: AssemblyCulture("en-US")]
    [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]

尝试查找以下页面指令属性:

Try to look for the following page directive attributes:

    <%@ Page Culture="en-US" UICulture="en-US" Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

尝试在web.configs一下:

Try to look in web.configs:

<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="false" />

编辑1

尝试寻找HttpHandlers的或的HttpModules试图设置语言

Edit 1

Try to look for HttpHandlers or HttpModules trying to set the language

试着在web.config层次看(在服务器,&LT;&的wwwroot GT; 表示您的IIS Web站点的根文件夹)

Try to look in the web.config hierarchy (at the server, <wwwroot> means the root folder of your IIS Web Site)


  1. 全球机。 &LT;&WINDIR GT; \\ Microsoft.NET \\框架\\&LT;&版本GT; \\ CONFIG \\ Machine.config中

  2. 根网站配置。 &LT;&WINDIR GT; \\ Microsoft.NET \\框架\\&LT;&版本GT; \\ CONFIG \\ Web.config文件

  3. 网站。 &LT;&的wwwroot GT; \\ Web.config文件

  4. Web应用程序。 &LT;&的wwwroot GT; \\&LT;&Web应用程序GT; \\ Web.config文件

  5. 文件夹。 &LT;&的wwwroot GT; \\&LT;&Web应用程序GT; \\&LT; D​​IR&GT; \\ Web.config文件

  1. Global machine. <windir>\Microsoft.NET\Framework\<ver>\Config\Machine.config
  2. Root Web config. <windir>\Microsoft.NET\Framework\<ver>\Config\Web.config
  3. Website. <wwwroot>\Web.config
  4. Web application. <wwwroot>\<webapp>\Web.config
  5. Folder. <wwwroot>\<webapp>\<dir>\Web.config

如果您有多个服务器(Web场),检查你将被重定向到正确的服务器(正在检查的配置之一),为了做到这一点,你可以使用所需的服务器的IP地址或配置主机在客户端计算机上的文件

If you have multiple servers (web farm), check you are being redirected to the correct server (the one you are checking the configuration), in order to do it you can use the ip of the desired server or configure your host files in your client computer

这篇关于正确的CurrentCulture默认为en-US在ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆