6

I used code below to get client ip with asp.net before but after I moved to VDS this function begin returning only my subnet mask which is 178.18.198.1 or 178.18.198.2. Can anyone help me with this problem?

Private Function GetIPAddress() As String
    Dim sIPAddress As String = Nothing
    sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

    If String.IsNullOrEmpty(sIPAddress) Then
        sIPAddress = Request.ServerVariables("REMOTE_ADDR")
    End If

    Return sIPAddress
End Function

EDIT

Found similar problem here:

Have deployed many 2008 32 bit standard web servers using the citrix netscaler isapi (the netscaler being a load balancer), in all cases the client IP address is logged in the standard IIS logs. On a new project I was asked to deploy 2008 R2, configured IIS 7.5 identically with how I configured IIS 7.0 in the past, this time however the client ip is returning the load balancer address in the logs. Here is the weird part, I installed "advanced logging" and it is showing the client IP address properly, so the isapi is doing its job. Have googled this one to death and could use some advice.

I also found ISAPI Filter module but cannot make it work: devcentral.f5.com/x_forwarded_for_log_filter_for_windows_servers

3
  • Figured out that HTTP_CLIENT_IP returns my right ip address but why this code is not working as previous??
    – HasanG
    May 16, 2011 at 8:43
  • A 3rd party module, written by one of F5’s architects devcentral.f5.com/articles/…
    – Kiquenet
    Nov 15, 2016 at 10:15
  • IIS7/8: Logging the real client IP in the IIS hit logs blogs.iis.net/deanc/… Options: Advanced Logging, ARR, F5 Module
    – Kiquenet
    Nov 15, 2016 at 10:22

2 Answers 2

4

Problem solved by using HTTP_CLIENT_IP instead of REMOTE_ADDR in sourcecode files.

The problem about IIS Logs was solved by installing IIS Advanced Logging module as suggested here. Also I got error "503: Service Unavailable" after installing Advanced Logging but solved this by granting read-write permissions to Everyone for Program Files\IIS folder and started failed application pools.

http://kb.parallels.com/6735

Another solution suggested here is:

On the NetScaler under "load balancing", "Services" then under the advanced tab, under settings, check the box for "Use Source IP" and "Client IP" then in the Header field "CLIENT-IP"

2
0

I use

IP.Text = Request.UserHostAddress;

In C#. Does that work for you?

5
  • No it is returning same address: 178.18.198.2
    – HasanG
    May 16, 2011 at 8:42
  • This works fine for me, it seems more an infrastructure issue
    – Pleun
    May 16, 2011 at 8:45
  • Asked question at serverfault, hope the problem solves: serverfault.com/questions/270751/server-records-wrong-ips
    – HasanG
    May 18, 2011 at 0:07
  • Its due to the IIS Proxy, I have same issue, unfortunately Pleun, the ip header is changed at the IIS Proxy / Proxy level.
    – Ian Jowett
    Oct 23, 2014 at 20:05
  • The same is Request.UserHostAddress.ToString(); and HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString()
    – Kiquenet
    Nov 15, 2016 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.