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 25, 2020, 7:37 PM EST
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 RajamanickamTOP 100Posted Apr 18, 2015, 8:06 PM EDT
Good one
NitinPosted Apr 12, 2015, 12:23 PM EDT
good one
Santhakumar MunuswamyPosted Apr 11, 2015, 6:07 AM EDT
Good