如何在dotnet隔离的Azure函数中获取客户端IP地址?
我正在使用Azure函数隔离在.NETCORE 6.0(C#)中编写功能,并且需要获取客户端的IP地址。 有什么方法可以从httprequestdata或functionContext对象获取客户端IP地址?
[Function("GetClientIP")]
public async Task<HttpResponseData> GetClientIP([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req, FunctionContext functionContext)
{ .... }
我已经提到了 link :但这不是用于隔离模式。
备注:我正在使用隔离模式。
I'm writing a function in .NetCore 6.0 (C#) using Azure Functions Isolation and need to get the ip address of the client.
Is there any way to get Client IP address from the HttpRequestData OR FunctionContext object?
[Function("GetClientIP")]
public async Task<HttpResponseData> GetClientIP([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req, FunctionContext functionContext)
{ .... }
I have referred following link: but it is not for ISOLATION mode.
Remarks: I am using ISOLATION mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于可以通过下面的代码来检索它。
请注意,仅在Azure内托管时,标题值“ X-Forwarded-For”才能可用。
在我的情况下,检索的值包含以下值
“ 105.224.244.204,147.243.88.136:58088”
列表中的第一个IP地址包含客户端IP地址。
我还发现我本可以用键值“ X-azure-clientip”检索它。原因是该功能托管在Azure前门后面。
该链接更详细地介绍了Azure前门后门托管时可以预期的标题
https://learlen.microsoft.com/en -us/azure/前门/前门 - http-headers-protocol
I was finally able to retrieve it by using the code below.
Please note that the header value "x-forwarded-for" is only available when hosted within azure.
In my case the retrieved value contained the following value
"105.224.244.204, 147.243.88.136:58088"
The first IP address in the list contains the client IP address.
I also discovered that I could have retrieved it with key value "x-azure-clientip". The reason for this is the function is hosted behind Azure Front Door.
The link goes into more detail about what headers can be expected on the request when hosted behind Azure Front Door
https://learn.microsoft.com/en-us/azure/frontdoor/front-door-http-headers-protocol