Ipapi provides an easy-to-use API interface allowing customers to look at various pieces of information IPv4 and IPv6 addresses are associated with. You can access this API with multiple languages through an HTTP request. is a very useful online tool/service that exists to resolve IPs to country codes/names. In this article, I will share with you 5 of the most awesome and free GeoIP databases that you can access nowadays. According to the type of implementation, you may read this information either from an API over HTTP or the specific GeoIP databases to obtain this information in JSON or XML format. Many alternatives to access information of this kind allow you to obtain as well more specific information as the city, state, province, local currency, latitude and longitude, company detail, ISP lookup (internet service provider), language, zip code, country calling code, time zone, current time, sunset and sunrise time, moonset and moonrise time from any provided IPv4 and IPv6 address. ViewBag.Message = "Your application description page.GeoIP refers to the method of obtaining the geographic location of a specific device by its IP. The code is similar to the controller redirection case but just the location of the attribute is on top of the specific actions. You can select which actions in particular you wish to execute the redirection code. This is the most granular redirection you can perform. ViewBag.Message = "Your application description page." Namespace RedirectVisitorsB圜ountryASPDotNetMVC.Controllers Your controller code will look something like below: using System To achieve this, you can add an attribute with the name of our action filter class on top of your controller class. It is sometimes necessary to redirect only specific controllers for security reasons. Public static void RegisterGlobalFilters(GlobalFilterCollection filters)įilters.Add(new Filters.RedirectVisitorsFilter()) // redirect globally Namespace RedirectVisitorsB圜ountryASPDotNetMVC Add 1 line containing our action filter class name to the code as below: using System.Web Look for the App_Start folder in your project and open the FilterConfig.cs file. For this purpose, you will need to redirect on a global level. Visitors from Europe may need to be redirected to a different website. Let’s say you have websites catering to various regions. The last option is to filter only specific controller actions. If you prefer a more granular approach, you can also apply the filter only on specific controllers. You could apply the filter on a global scale where every action will be redirected if the country of the IP address is in our specified list. NOTE: The IP2Location Web Service is returning the geolocation in the form of JSON hence our use of a regular expression to extract the country code.Īction filters can be applied on 3 different levels depending on your needs. This is the URL that the code will be redirecting to if the visitor’s detected country is in the RedirectCountries list. Feel free to edit the URL inside RedirectResult to another website if you so wish. You can also change the RedirectCountries to test other countries. Task data = httpClient.GetStringAsync("" LicenseKey "
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |