UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Find Public IP Address - Asp.Net

Demo and code how to find Public IP address In Asp.net

by Athil


Posted on 27 Jun 2018 Category: Asp.net Views: 119

Edited on 11 Jul 2019


Here I am going to show how to find public IP address In Asp.net

DEMO

C#

ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

Full Demo Code

Aspx

<form id="form1" runat="server">
    <div>
    <h1> Demo for find Ip address Asp.net C# </h1>
       
        
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Get Ip address" OnClick="Button1_Click" />

    </div>
    </form>

C#

        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = GetIPAddress();
        }
        public string GetIPAddress()
        {
            string ip;
            ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ip == "" || ip == null)
                ip = Request.ServerVariables["REMOTE_ADDR"];
            return ip;
        }

 



Leave a Comment:


Advertisement