Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 583
nothrow Avatar asked Feb 19 '23 08:02

nothrow


1 Answers

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)

like image 58
Hans Kesting Avatar answered Mar 04 '23 22:03

Hans Kesting