在Azure功能中获取远程IP地址 [英] Get remote IP address in Azure function

查看:239
本文介绍了在Azure功能中获取远程IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get remote IP address in Azure function?

HttpRequestMessage MS_HttpContext 属性c>,因此我无法在此处使用解决方案:如何在Azure Functions C#中获取客户端IP地址?

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#?

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

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?

推荐答案

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

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

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

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)

然后获取远程IP

var remoteAddress = req.HttpContext.Connection.RemoteIpAddress;

这篇关于在Azure功能中获取远程IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆