0

I'm using the code:

CultureInfo.CurrentCulture

Within my asp.net app. My question is how this is determined. Is it the location of the IIS server, browser, user’s local machine, etc...?

I need to ascertain the location of a web user. Due to unforeseen reasons the IP address doesn’t work (internal problem out of scope for this discussion), browser region info doesn’t work (incorrect default language)

Andyww
  • 209
  • 3
  • 13
  • Well, iIt's a duplicate of this (unanswered) http://stackoverflow.com/questions/26583257/how-is-cultureinfo-currentculture-determined Here's another: http://stackoverflow.com/questions/9697604/from-where-cultureinfo-currentculture-reads-culture – Tim Schmelter Oct 17 '16 at 07:54
  • 'changing the system local' does that means the users system or the server ? – Andyww Oct 17 '16 at 07:55
  • For what purpose: determining the language or determining formatting options? What about the accept-header? What about having the user select his region and storing that in e.g. a cookie? – Bernhard Hiller Oct 17 '16 at 07:56
  • Yes, thats my current thinking, having some kind of prompt to allow the user to input their location – Andyww Oct 17 '16 at 08:00

2 Answers2

0
CultureInfo.CurrentCulture

Gets or sets the CultureInfo object that represents the culture used by the current thread.

Since you're asking about ASP.NET we are always talking about the server culture and not the client.

The current culture is a property of the executing thread, which is returned by the static Thread.CurrentThread property. The value of the CultureInfo.CurrentCulture property corresponds to the value of the Thread.CurrentCulture property. Retrieving the value of the CultureInfo.CurrentCulture property is equivalent to retrieving the CultureInfo object returned by the Thread.CurrentThread.CurrentCulture property. Starting with the .NET Framework 4.6, setting the value of the CultureInfo.CurrentCulture property also changes the current thread culture.

https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture(v=vs.110).aspx

Ted
  • 3,985
  • 1
  • 20
  • 33
0

The culture is set by default based on the culture settings of the system you are running on, for example the Windows regional settings. You cannot use this to get a user location. You would need the IP for that (and then again, you cannot rely on that 100%).

  • 1
    Thats should be fine, so if a user is based in France, it'll report fr-FR even if the site is hosted in USA – Andyww Oct 17 '16 at 07:58
  • The code running on the server will report the US culture. The users browser would probably report France, depending on the users settings on that machine. If they were running a .net app on their machine in France and it connected to a server in the US the code running on their machine would report their culture, it would not affect the servers culture. – Aran Mulholland Mar 20 '19 at 05:49