本文介绍了如何在Azure Functions C#中获取客户端IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Azure函数在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地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!