How do you get the IP address from a request in ASP.NET?

Carson picture Carson · May 15, 2009 · Viewed 46.4k times · Source

I have been trying to figure this out but cannot find a reliable way to get a clients IP address when making a request to a page in asp.net that works with all servers.

Answer

TheVillageIdiot picture TheVillageIdiot · May 15, 2009

One method is to use Request object:

protected void Page_Load(object sender, EventArgs e)
{
    lbl1.Text = Request.UserHostAddress;
}