Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 529.7k

I.P Address

Jan 21 2024 6:19 AM

Hi

  I have below code but it is returning :: 1

private string GetIpAddress()
        {
             

            string IpAddress = string.Empty;

            try
            {
                IpAddress = Request.ServerVariables["HTP_X_FORWARDED_FOR"];

                if (IpAddress == " " || IpAddress == null)
                {
                    IpAddress = Request.ServerVariables["REMOTE_ADDR"];

                    return IpAddress;
                }
                else
                {
                    return IpAddress;
                }
            }
            catch (ArgumentNullException Exc)
            {
                Label2.Text = "Application Error : " + Exc.Message;
                return IpAddress;
            }
            catch (InvalidCastException Exc)
            {
                Label2.Text = "Application Error : " + Exc.Message;
                return IpAddress;
            }
            catch (InvalidOperationException Exc)
            {
                Label2.Text = "Application Error : " + Exc.Message;
                return IpAddress;
            }
            catch (NullReferenceException Exc)
            {
                Label2.Text = "Application Error : " + Exc.Message;
                return IpAddress;
            }
            catch (Exception Exc)
            {
                Label2.Text = "Application Error : " + Exc.Message;
                return IpAddress;
            }

            
        }

Thanks


Answers (3)