Question

My ASP.NET application checks the IP of the calling client.

But I have to host it behind a Linux-Box where Apache redirects it to an internal Windows 2003 Server running IIS like:

ProxyPass /srs http://192.168.21.15/srs/

where 192.168.21.15 is the internal IP of the Windows-server, and 192.168.21.1 the internal IP of the Linux box that gets the request from the internet.

Now, it seems to me that requests from the intERnet that are forwarded to w.x.y.15 all seem to origin from w.x.y.1

How can I preserve (or forward) the original IP?

I heard about X-forwarded-for... but how do I retrieve this value in C# ??

Thank you, Reinhard

Was it helpful?

Solution

In general if a proxy server modifies the IP address information the original IP address is stored in the HTTP_X_FORWARDED_FOR server variable. To access this in ASP.NET using C# you can use:

Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

OTHER TIPS

For java candidates, you can use:

String ipAddress=request.getHeader("X-Forwarded-For");

If you will use request.getRemoteAddr(), it may return 127.0.0.1 if there has been Apache redirection at your deployment server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top