- Home
- .NET code examples
- Geolocation & IP lookup example to find client's location
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.
C# coding challenges
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.
- Visual Studio 2022. Version 17.10.2 or above. It will work with the free community version.
- .NET 8 SDK. Version 8.0.6 or above.
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.