在 Azure 函数中获取远程 IP 地址

Mar*_*cik 4 c# azure .net-core azure-functions

如何在 Azure 功能中获取远程 IP 地址?

MS_HttpContext属性中不存在该属性HttpRequestMessage,因此我无法在此处使用解决方案:How to get client IP address in Azure Functions C#?

获得 IP 地址的转发很容易(从标题中,如上面的链接所示),但我怎样才能获得远程 IP 地址?

Jer*_*Liu 6

对于 .NET Core Functions,我们通常使用Microsoft.AspNetCore.Http.HttpRequest.

当我们创建一个Http触发器模板时,我们可以看到它。

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

然后获取远程IP

var remoteAddress = req.HttpContext.Connection.RemoteIpAddress;
Run Code Online (Sandbox Code Playgroud)