Find IP Address Location By Country in ASP.Net

·

Being able to tell on-the-fly which country your visitors come from is a big boon. The applications are numerous. You can use it to extend your security by limiting to certain countries only. Or perhaps you want present a different page or ad per country. Or you just want to automatically select the country in the dropdown of your forms.

Fortunately, thanks to MaxMind, this is all free and easy. Here are 5 simple steps:


1. Download API files and extract
2. Copy CountryLookup.vb to you App_Code folder or Class Library
3. Download Database and extract
4. Copy GeoIP.dat and place it on your website.
5. Start using it.

Dim _UserIPAddress As String = Me.Page.Request.UserHostAddress
Dim _IPDataPath As String = Me.Page.Server.MapPath("data/GeoIP.dat") 'relative path to the Geo IP Database.
Dim _CountryLookup As CountryLookup = New CountryLookup(_IPDataPath)
Dim _CountryName As String = _CountryLookup.LookupCountryName(_UserIPAddress)
Response.Write(_CountryName)


C# API is also available here as well as other programming languages. APIs also come with country flag images which you can use to create cool user interfaces.


0 comments: