【发布时间】:2021-08-19 16:21:15
【问题描述】:
我在 web api 中使用微软的 APIController,我想查看有关请求者的信息,例如 IP 以及我能找到的有关请求者的任何其他信息。浏览器
public class ExampleController : ApiController
{
[HttpGet]
[HttpPost]
public HttpResponseMessage GetStuff(HttpRequestMessage message)
{
//get info about caller, maybe using
//HttpContext.Current.Request. something
var requestorIP = ????
}
}
【问题讨论】:
-
您使用的是 ASP.NET Core 还是旧的 ASP.NET 5?
-
@DavidG 你的意思是 ASP.NET 4?
-
@mason 哈哈是的,天哪,这些版本号太痛苦了
-
@mason 等等,不,它是 MVC 5 不是吗? en.wikipedia.org/wiki/ASP.NET_MVC#Release_history
-
无论如何,关于如何做到这一点已经有几十个问题了。
标签: c# asp.net-web-api