In most of the scenario’s the user IP address will be tracked with the last gate way by which request was forwarded. Here we will discuss about the IP Address tracking of user with the Proxy, gateway and user machine’s IP.
Example
- private static string Fetch_UserIP()
- {
- string VisitorsIPAddress = string.Empty;
- try
- {
- if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
- {
- VisitorsIPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
- }
- else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
- {
- VisitorsIPAddress = HttpContext.Current.Request.UserHostAddress;
- }
- } catch (Exception ex)
- {
- //Handle Exceptions
- }
- return VisitorsIPAddress;
- }
- HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
- HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

Ankur VermaPosted Jan 26, 2020, 12:37 AM
To obtain the login user IP Address we can use the "REMOTE_ADDR" and "HTTP_X_FORWARDED_FOR" Variable which provides us the IP Address of the remote host that is making the request. https://www.hackhackathon.com/aspnet-mvc/how-to-get-the-login-user-ip-address-in-net-mvc-c-sharp
Gowtham RajamanickamPosted Apr 19, 2015, 12:06 AM
Good one
NitinPosted Apr 12, 2015, 4:23 PM
good one
Santhakumar MunuswamyPosted Apr 11, 2015, 10:07 AM
Good