UserHostAdress question

Answered
1
0

I run my WiseJ application behind a reverse proxy (traefik) and try to detect the users IP address using “Application.UserHostAddress”.
This seems to provide the local/private IP address of the client (e.g. 192.168.x.x).
Is it also possible to get the public IP address of the internet router ? In another ASP.net Core application I use “HttpContext.Request.Headers[“X-Real-Ip”]” for detecting the IP which provides the public IP.

  • You must to post comments
Best Answer
0
0

Application.UserHostAddress is the same as HttpRequest.UserHostAddress which corresponds to “REMOTE_ADDR” (https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524602(v=vs.90)). All server variables are available as Application.ServerVariables[name].

Usually proxies add “X-Forwarded-For”, but “X-Real-IP” could work if available. Try with Application.ServerVariables. If it’s not there, you can always use HttpContext.Current.Request.Headers in Program.Main since it’s the first HTTP request.

  • You must to post comments
1
0

Wisej simply passes on all server variables and headers received by the server. You can also try with the self hosting option we already have using Katana, which is also Microsoft’s implementation of OWIN.

  • You must to post comments
1
0

Thank you Luca. It took a while but now I could make it work using Application.ServerVariables[“HTTP_X_REAL_IP”] to get the information I need.
Do you know if this will still work work once using WiseJ for .net Core (without IIS but e.g. Kestrel) ?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.