Get User IP Address - C#

Get User IP Address - C#

code snippet

c#
protected string GetIPAddress()
{
   System.Web.HttpContext context = System.Web.HttpContext.Current;
   string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
   if (!string.IsNullOrEmpty(ipAddress))
   {
        string[] addresses = ipAddress.Split(',');
        if (addresses.Length != 0)
        {
            return addresses[0];
        }
   }
   return context.Request.ServerVariables["REMOTE_ADDR"];
}

"Thinking: the talking of the soul with itself"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.