How to get IP Of Client machine in ASP.Net


  1. IP Of Client machine
  2. the following function is used to get IP of Client Machine


Public string GetIPOfClient()
        {
            string returnvalue = string.Empty;
            try
            {
                System.Web.HttpContext context = System.Web.HttpContext.Current;
                string ip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                returnvalue = context.Request.ServerVariables["REMOTE_ADDR"];
                if (!string.IsNullOrEmpty(ip))
                {
                    string[] addresses = ip.Split(',');
                    if (addresses.Length != 0)
                    {
                        returnvalue = addresses[0];
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
            }
            return returnvalue;
        }

Comments

Popular posts from this blog

String Program in C#

CSV using XmlNode

Extension Method & Partial Class