如何在 Azure Functions C# 中获取客户端 IP 地址? [英] How to get client IP address in Azure Functions C#?
本文介绍了如何在 Azure Functions C# 中获取客户端 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Azure Functions 用 C# 编写一个函数,需要获取调用该函数的客户端的 IP 地址,这可能吗?
I'm writing a function in C# using Azure Functions and need to get the ip address of the client that called the function, is this possible?
推荐答案
这里是一个基于 此处.
#r "System.Web"
using System.Net;
using System.Web;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
string clientIP = ((HttpContextWrapper)req.Properties["MS_HttpContext"]).Request.UserHostAddress;
return req.CreateResponse(HttpStatusCode.OK, $"The client IP is {clientIP}");
}
这篇关于如何在 Azure Functions C# 中获取客户端 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文