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
HttpContext.Current.Request.UserHostAddress is what you want.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With