Get the Host name and IP address from ASP.NET

To get the Host name and IP address from your ASP.NET application, we have option is .NET. Using the using System.Net; namespace you have access to the classes which can expose the Host name and IP address.

The sample code to explain the solution. Paste the same code in the page load event of the ASP.NET page.

using System.Net;
//Get the Host name
string strHostName = string.Empty;
strHostName = Dns.GetHostName();
// Then using host name, get the IP address list..
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
//Get the IP address
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
Response.Write("IP Address {0}: {1} " + i + addr[i].ToString() + ", HostName: " + strHostName);


Thank you very much, i was stuck with this problem, i have found it and it is working fine,


Saif ur rehman saifi
Islamabad, Pakistan
firas rehawi said…
Dear, Thanks For This easy and useful code, but this code to get the host info. but how to get the Client ip and computer name to use it in MaintenanceRequest.


Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

Windows Server AppFabric: installation error , While installing SharePoint prerequisite installer