WinForms != WebForms

by Michael S. Kaplan, published on 2006/12/18 03:03 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/12/18/1314538.aspx


The question Peter asked was:

Is there a DateTime Difference on WinForm and WebForm?

I write a simply code to see the difference:


    this.label1.Text = DateTime.Now.ToString();
    this.label1.Text += " " + System.Globalization.CultureInfo.CurrentCulture.ToString();

The output of WinForm is “28/11/2006 11:03:21 en-GB”, while WebForm is “11/28/2006 11:02:55 AM en-US”.

Even I restart my computer, the difference is still on.

Can you explain this difference, and how to avoid it?
 

Well, the fundamental issue is of course that in general, WinForms are not WebForms. :-)

In particular, they run under different user accounts, which are of course not guaranteed to be set to the same user default locale in unmanaged code or the same CurrentCulture in manged code.

In addition, one is run on the server side on a web server, whilc the other is run on the client side in an application.

In general, people tend to not change the settings in non-interactive accounts even on their own machines and people tend to usually not have much control over a web server's accounts anyway, so it is quite common to see a WebForm return an en-us result even if very non-en-us results might be otherwise expected.

Given that, I would say that relying on CurrentCulture in such cases (unless a web app sets it explicitly to match accept language or other settings) is probably a mistake....

 

This post brought to you by £ (U+00a3, a.k.a. POUND SIGN)


no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day