What is the correct way of obtaining the remote IP address (the address of the client making the request) in an Azure durable function?
The beginning of my HttpStart method
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "report-data/get")]
HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter, ILogger log)
{
I tried
((HttpContext)req.Properties["MS_HttpContext"]).Connection.RemoteIpAddress.ToString();
but the MS_HttpContext
property is missing.
I also tried
string result = string.Empty;
if (req.Headers.TryGetValues("X-Forwarded-For", out IEnumerable<string> headerValues))
{
result = headerValues.FirstOrDefault();
}
return result;
which returns and empty string.
I have looked at this similar question, but it assumes the request is of type HttpRequest
. In my case, it is HttpRequestMessage
.
This answer suggests that the X-Forwarded-For
header must be enabled first. But I don't know how to do this in my Azure Function App (or for my durable function).
I am developing my Azure functions locally, using VS Code.