Get ClientIP Address Behind LoadBalancer RRS feed

  • Question

  • User-903626278 posted

    I have a cisco load balancer and 2 DMZ Servers. I need to capture the client ip address in my webservice. I have tried all but no luck...what should I do?

    string srvVars=HttpContext.Current.Request.ServerVariables["HTTP_X_COMING_FROM"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_VIA"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_COMING_FROM"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED_FOR"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_FROM"] + " ," +
    HttpContext.Current.Request.ServerVariables["HTTP_PROXY_CONNECTION"] + " ," +
    HttpContext.Current.Request.ServerVariables["CLIENT_IP"] + " ," +
    HttpContext.Current.Request.ServerVariables["REMOTE_HOST"] + " ," +
    HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] + " ," +

    All returning BLANK except for REMOTE_HOST and REMOTE_ADDR which is returning my Load Balancers IP Address!!!!

    Wednesday, October 10, 2012 10:05 AM

All replies

  • User-1662538993 posted

    Try this -


    Wednesday, October 10, 2012 2:50 PM
  • User-1000095884 posted

    Hi mettlus,

    You should configure the LoadBalancer for client IP forwarding, then try following code to get the client IP address.


    Hope it helps.

    Best Regards,<!--EndFragment-->

    Wednesday, October 10, 2012 11:30 PM
  • User-903626278 posted

    Apparently IIS log has the client IP Address, my network guy can't do any config changes since he pointing out that IIS has the IP Address in the log [why can't u].

    I am looking to get the IP Address captured in my web-service :(


    Thursday, October 11, 2012 11:01 AM
  • User-963541686 posted

    this is the piece of code i was using. this is working fine

     var clientEndpoint =
                        OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as
                    if (clientEndpoint != null)
                        var ClientMachineName = clientEndpoint.Address;

    [Note: this might show incorrect data in the local machine]

    Tuesday, October 16, 2012 1:30 AM
  • User-903626278 posted

    I am using Legacy WebService (ASMX) :(

    Tuesday, October 16, 2012 9:44 AM
  • User-903626278 posted

    Already did

    Tuesday, October 16, 2012 9:46 AM
  • User-770082400 posted

    To get the Client IP we need to configuration them in Load balancer itself. For some Load balancers we need to configure them in ISAPI Filters with custom dll's.

    Wednesday, November 28, 2012 2:35 PM
  • User-1649978604 posted

    Hi mettlus,

    How did you do that? Can not find a solution.


    Friday, May 3, 2013 8:27 PM
  • User1875775546 posted

    Most external load balancers use x-forwarded-for or similar http headers, check with wireshark for these headers which contain the external Ip address, if not present then get load balance guys to change the config.

    You then have a couple of options, download and install an Isapi filter from F5 (https://devcentral.f5.com/blogs/us/x-forwarded-for-log-filter-for-windows-servers) its free and works, or use IIS advanced Logging if you have IIS 7.5.

    This will get the client IP correctly inserted in the IIS logs, but to use the client IP in your code you have to get the value from the x-forwardedFor server variable, the name of this server variable (or header name0 can vary depending on load balancer, so check with wireshark first.

    see this page for sample code: http://stackoverflow.com/questions/2577496/how-can-i-get-the-clients-ip-address-in-asp-net-mvc

    hope it helps because its been a learning curve for me these past few days



    Tuesday, May 21, 2013 6:45 AM
  • User952158763 posted

    Hi Steve,

    Thanks for your reply. I am facing one issue with the implementation part. My web application is hosted on a Windows 2003 server machine and I have used the below steps,

    1. Downloaded the file and transferred the dll from \x64\Release folder in a New folder of the server C:\ISAPIFilters. 

    2. Right clicked on the IIS and select Properties.  Then selected the "ISAPI Filters" tab.  From there clicked the "Add" button and entered "F5XForwardedFor" for the Name and the path to the file "c:\ISAPIFilters\F5XForwardedFor.dll" to the Executable field. Clicked Ok. 

    however found that the Status of the Filter is showing as "NOT LOADED" in the IIS.

    Also to confirm you that I am receiving NULL values in the X-Forwarded-For Server variable.

    Please could you help me on this?



    Tuesday, July 9, 2013 7:12 AM