How to get/show current IP Address in asp.net c#

In this article, how to get/show current IP address in asp.net c# on page load.



Code behind(C#)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class ipaddress : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string currentipaddress;
        currentipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (currentipaddress == "" || currentipaddress == null)
        {
            currentipaddress = Request.ServerVariables["REMOTE_ADDR"];
            ipaddressresult.Text = currentipaddress;
        }
    }
}


Out-Put:-



How to get/show current IP Address in asp.net c# How to get/show current IP Address in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 9:25:00 AM Rating: 5

No comments:

Powered by Blogger.