I have developed a web application that is deployed as a web app on Azure.
I need to get the client's IP address such that I can use a GeoIP API to get the country from which the client is connecting.
So here's my question, how can I get the client's IP address when they send a request to view the homepage? I am using ASP.NET MVC.
To find the outbound IP addresses currently used by your app in the Azure portal, click Properties in your app's left-hand navigation. They are listed in the Outbound IP Addresses field.
ASP.NET web apps are cross-platform and can be hosted on Linux or Windows. When you're finished, you'll have an Azure resource group consisting of an App Service hosting plan and an App Service with a deployed web application.
However, to configure your IP whitelist for a specific web application, navigate to Settings, Networking, <the Web App overview page>. Under IP restrictions, click Configure IP restrictions.
Try this (verified on an Azure Web App using ASP.NET Core 2.x):
using Microsoft.AspNetCore.Http.Features;
using System.Net;
....
var connection = HttpContext.Features.Get<IHttpConnectionFeature>();
IPAddress clientIP = connection.RemoteIpAddress;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With