【问题标题】:Is there a way to get requestor info in C# apiController [duplicate]有没有办法在 C# apiController 中获取请求者信息 [重复]
【发布时间】: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


【解决方案1】:

貌似可以通过Context.Connection.RemoteIpAddress获取远程IP地址,远程端口也在连接对象上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-13
    • 2018-01-16
    • 2022-10-25
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多