Last post Jul 06, 2017 11:51 AM by PatriceSc
Jul 06, 2017 09:03 AM|tapan2017|LINK
i know that HttpContext.Current.Request.UserHostAddress return client IP but not sure does it return client ip when user is behind firewall ?
how to get client ip from wherever scenario is there at user end.
Jul 06, 2017 09:16 AM|PatriceSc|LINK
You could also check https://en.wikipedia.org/wiki/X-Forwarded-For first (for example
https://stackoverflow.com/questions/6316796/read-x-forwarded-for-header ) but the bottom line is that it should be just for information rather than something that is an essential application part.
What will you do with the IP address ?
Jul 06, 2017 09:47 AM|tapan2017|LINK
i need to develop a IP blocker. so some how i need to get client IP.
Jul 06, 2017 11:11 AM|PatriceSc|LINK
Another option could be to handle that at the web server level using https://www.iis.net/configreference/system.webserver/security/ipsecurity (or perhaps
Jul 06, 2017 11:20 AM|tapan2017|LINK
thanks for answer. instead of doing it can we do it in web.config file like below one ?
<location path="Default Web Site">
<add ipAddress="192.168.100.1" />
<add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
if we restrict ip in web.config file then we need to setup or configure anything in IIS?
Jul 06, 2017 11:51 AM|PatriceSc|LINK
In the web.config file, system.webServer should be directly under configuration (location is to aply something to a particular location inside your app).
Other problems could be :
- you likely have to install this feature as part of IIS (using the UI or PowerShell)
- the IIS configuration system is a hierarchy so that you can define some settings from the server down to particular folder. You can also control if a setting defined at a level can be overriden at a lower level. So you may have to allow this section at the
web.config level if you really want to define that for a particular application.