[英]How to get client's IP address on an Azure Web App developed in ASP.NET?
I have developed a web application that is deployed as a web app on Azure. 我已经开发了一个Web应用程序,该应用程序被部署为Azure上的Web应用程序。
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. 我需要获取客户端的IP地址,以便可以使用GeoIP API来获取客户端所连接的国家/地区。
So here's my question, how can I get the client's IP address when they send a request to view the homepage? 因此,这是我的问题,当客户发送请求查看主页时,如何获取客户的IP地址? I am using ASP.NET MVC.
我正在使用ASP.NET MVC。
Try this (verified on an Azure Web App using ASP.NET Core 2.x): 尝试以下操作(在使用ASP.NET Core 2.x的Azure Web App上进行验证):
using Microsoft.AspNetCore.Http.Features;
using System.Net;
....
var connection = HttpContext.Features.Get<IHttpConnectionFeature>();
IPAddress clientIP = connection.RemoteIpAddress;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.