ASP.NET application doesn't reflect Regional settings

邮差的信 提交于 2019-11-30 09:29:18

问题


I've set, in my regional settings (for Czech, culture cs-CZ), the short time / long time pattern to following:

  • Short time: H.mm
  • Long time: H.mm.ss

I'm trying to use those settings in C# applications. In following console app, everything works:

using System; using System.Globalization;

class Program
{
    static void Main()
    {

        Console.WriteLine(CultureInfo.CurrentCulture.Name);
        Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern);

        Console.ReadLine();
    }
}

The output is, as I thought, following:

cs-CZ
H.mm.ss

I've created ASP.NET application, which, to my uttermost surprise, doesn't reflect this.

Minimal example:

<%@ Page Language="C#" %>

<%= System.Globalization.CultureInfo.CurrentCulture.Name %><br />
<%= System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern %>

Output:

cs-CZ
H:mm:ss

I've tried restarting, .NET2.0, .NET4.0, still no effect.

Note - This issue raised as a part of bug, where we forgot to include InvariantCulture for DateTime.ToString(), which should then be parsed by JSON deserializer. (The guy with this problem has somewhat different Time format separator).

Fixing the issue with re-creating CultureInfo isn't something I'm looking for, I just want to see the reason, as I wasn't able to reproduce the issue with any means.


回答1:


The problem is that the Regional Settings are user specific. You changed them for you, but the site runs as a different user (see the app-pool in IIS)



来源:https://stackoverflow.com/questions/13645441/asp-net-application-doesnt-reflect-regional-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!