In the Asp.Net Core core, how do I get the IP address of a website?

In web forms, if I need to get the IP address of a website server (say, for logging), I could get it from request.ServerVariables["LOCAL_ADDR"]

How can I get it in Asp.Net Core when working in Kestral for IIS or IIS Express?

+4
source share
1 answer

You can use HttpContext.Features.Get<IHttpConnectionFeature>()- docs :

var httpConnectionFeature = httpContext.Features.Get<IHttpConnectionFeature>();
var localIpAddress = httpConnectionFeature?.LocalIpAddress;
+7
source

Source: https://habr.com/ru/post/1659431/


All Articles