Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the caller's IP address in a WebMethod?

How do I get the caller's IP address in a WebMethod?

[WebMethod]
public void Foo()
{
    // HttpRequest... ? - Not giving me any options through intellisense...
}

using C# and ASP.NET

like image 314
Guy Avatar asked Sep 24 '08 22:09

Guy


2 Answers

HttpContext.Current.Request.UserHostAddress is what you want.

like image 73
Darren Kopp Avatar answered Nov 18 '22 19:11

Darren Kopp


Just a caution. IP addresses can't be used to uniquely identify clients. NAT Firewalls and corporate proxies are everywhere, and hide many users behind a single IP.

like image 9
davenpcj Avatar answered Nov 18 '22 21:11

davenpcj