5

How can I get remote IP address in Azure function?

The MS_HttpContext property is not present in the properties of HttpRequestMessage, so I cannot use the solution here: How to get client IP address in Azure Functions C#?

Getting Forwarded For IP address is easy (from the headers, as shown in the link above), but how can I get the remote IP address?

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
Martin Staufcik
  • 8,295
  • 4
  • 44
  • 63

1 Answers1

7

For .NET Core Functions, we usually use Microsoft.AspNetCore.Http.HttpRequest.

When we create a Http trigger template, we can see it.

    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)

Then get remote IP

var remoteAddress = req.HttpContext.Connection.RemoteIpAddress;
Jerry Liu
  • 17,282
  • 4
  • 40
  • 61