Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
761 views
in Technique[技术] by (71.8m points)

.net - ASP.NET application doesn't reflect Regional settings

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

Settings

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...