0

ASP.NET:

For a new web visitor, how can we get the default currency that they use?

E.g. if they are browsing from a web browser in Canada, how can we get (in some aspx.vb code) "CAD" so we can display that on page1.aspx?

user1946932
  • 474
  • 1
  • 16
  • 41
  • What have you tried, and how has what you've tried failed? Ideally, you should provide a [MCVE] of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. [SO] is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See [Ask] a Good Question. – Jeff Zeitlin Dec 19 '19 at 20:25
  • 1
    For the record, you won't get that information from the browser. You will need to get the culture for the browser and then map that to a currency code yourself. – jmcilhinney Dec 20 '19 at 01:22

2 Answers2

2

There is no browser API to get the user's currency.

There are various ways of determining the user's location, including IP lookups and the Geolocation API. A full list of options is shown on this StackOverflow answer.

You would then need a lookup table to map countries to currencies.

If most of your customers come from one country, it may be easiest to default to that currency and provide a dropdown box for them to change it if needed.

James
  • 7,343
  • 9
  • 46
  • 82
1

You can get the user IP address and then detect their country of origin. From the country information, you can display the appropriate currency.

I found one 3rd party site with ASP sample codes (need to modify it to VB.NET).

https://blog.ip2location.com/knowledge-base/display-visitors-country-currency-using-asp-and-ms-sql-database/

Michael C.
  • 1,410
  • 1
  • 9
  • 20