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
- string clientAddress = HttpContext.Current.Request.UserHostAddress;
For self hosted, you can access your client address via the following:
Code Snippet
- object property;
- Request.Properties.TryGetValue(typeof(RemoteEndpointMessageProperty).FullName, out property);
- RemoteEndpointMessageProperty remoteProperty = property as RemoteEndpointMessageProperty;
Hope this helps.