Google Groups

Re: [ServiceStack] How to get the ip address of the client posting to a service.

mythz May 23, 2012 2:19 PM
Posted in group: ServiceStack .NET Open Source REST Web Services Framework
base.RequestContext.Get<IHttpRequest>().UserHostAddress returns the (for ASP.NET) which *is* the IP host address of the remote client.

If your services is being accessed through a proxy then this will be the proxy servers IP address and you will need to inspect the X-Forwarded-For HttpHeader to get the remote IPAddress their proxying, An example of how to get that is here:

ForwardedFor = httpReq.Headers[HttpHeaders.XForwardedFor],


On Wed, May 23, 2012 at 5:09 PM, Alex C <> wrote:

I'm having trouble with this.
The base.RequestContext.Get<IHttpRequest>().UserHostAddress is giving back the actual IP from the service and not the user. I'm not sure how exactly I'm supposed to get the user's ip.


On Wednesday, May 23, 2012 1:23:42 PM UTC-4, mythz wrote:
You can access the IpAddress which is available from the RequestContext from your services with:

var ipAddr = base.RequestContext.IpAddress;

You can get access more info about the Request from the IHttpRequest:

var httpReq = base.RequestContext.Get<IHttpRequest>();

Finally you can get access to the original ASP.NET HttpRequest with:

var aspnetReq = (HttpRequest).OriginalRequest;


On Wed, May 23, 2012 at 1:00 PM, Alex C <> wrote:

I'm new to ServiceStack and I need to find out the IP address of the client talking to the service.
Basically I have a service talking to different clients, and I need to save each client's IP server side.


- Demis

- Demis