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

时间:2018-11-08 16:16:44

标签: c# azure .net-core azure-functions

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

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

获得IP地址的转发很容易(从标题,如上面的链接所示),但是如何获取远程IP地址?

1 个答案:

答案 0 :(得分:2)

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

创建Http触发器模板时,可以看到它。

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

然后获取远程IP

var remoteAddress = req.HttpContext.Connection.RemoteIpAddress;
相关问题