Geolocation & IP lookup example to find client's location

Download our Geolocation example in an ASP.NET Core Web API so you can do an IP address lookup on a client's IP address and find out the city and country where they are located.

This example uses MaxMind's GeoLite2 and includes an example using the GeoLite2 City and GeoLite2 Country database.

It also uses the MaxMind.GeoIP2 NuGet package to perform the IP address lookup.

There are separate endpoints to find the country and also an additional one to return the city as well.

Software

This is the software that will need to be installed onto your machine.

Get the application working

You'll need to fill out the code example form. We will send you an email where you can download the code example.

Open the project in Visual Studio

Open up RoundTheCode.GeoIp.sln in Visual Studio 2022.

Start the project in Visual Studio. It will load up https://localhost:9952.

Test out the endpoints by adding an IP address to them.

More information

Watch our video where we show you how to integrate geolocation into your .NET project using the MaxMind.GeoIP2 NuGet package.

In-addition, read our tutorial for more information on how to perform an IP lookup on a client so you can return their country.