在Azure功能中获取远程IP地址 [英] Get remote IP address in Azure function
问题描述
如何在Azure功能中获取远程IP地址?
How can I get remote IP address in Azure function?
HttpRequestMessage $ c $的属性中没有
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屋!