Asp Net Web API 2.1 get client IP address

后端 未结 9 1067
逝去的感伤
逝去的感伤 2020-11-27 11:12

Hello I need get client IP that request some method in web api, I have tried to use this code from here but it always returns server local IP, how to get in correct way ?

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 11:38

    string userRequest = System.Web.HttpContext.Current.Request.UserHostAddress;
    

    This works on me.

    System.Web.HttpContext.Current.Request.UserHostName; this one return me the same return I get from the UserHostAddress.

提交回复
热议问题