Web application, getting the IP-Adress

Hi Marco,

This really depends on how you’re deploying your app. For example, if there is a CDN in front of your web application, it will vary.

As an starting point:

Var ipHeaders() As String = Array("X-Forwarded-For", "Remote-Addr")

For Each ipHeader As String In ipHeaders
  Var value As String = Header(ipHeader)
  If value <> "" Then
    Return value
  End If
Next

Return RemoteAddress

This will try to find the IP in that specific order, you may want to adjust this to your needs. If it can’t be found in the headers, it will use the remote socket address.

Please note some proxies will return a list of comma-separated IPs.