In this article we will learn how to
get Local IP Address of the client system in asp.net.
Description: In previous articles I have explained Error:
ASP.NET:
How to Get Public IP address in ASP.NET using C# & VB.NET? And Custom
Validator: Server Side validation using Custom Validator in ASP.NET (C# &
Vb.NET) And ASP.NET:
Bind or Populate Form View Data control with data from SQL database using c#
& vb.net .
Demo:
In this example I have written the code on Button Click
Event:
Asp.NET Code to get Public IP address:
In C#:
Add Following NameSpaces :
using System.Net;
using System.Net.Sockets;
Now
Write Following Code:
protected string GetIPAddress()
{
return Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip
=> ip.AddressFamily == AddressFamily.InterNetwork).ToString();
}
protected void btnIpAddress_Click(object sender, EventArgs e)
{
string ipAddress =
GetIPAddress();
Response.Write("IP Address: " + ipAddress);
}
|