次の方法で共有


How to access the Client's IP address in Web API

For web hosted, you can access your client address via the following:

Code Snippet

  1.             string clientAddress = HttpContext.Current.Request.UserHostAddress;

For self hosted, you can access your client address via the following:

Code Snippet

  1.             object property;
  2.             Request.Properties.TryGetValue(typeof(RemoteEndpointMessageProperty).FullName, out property);
  3.             RemoteEndpointMessageProperty remoteProperty = property as RemoteEndpointMessageProperty;

Hope this helps.