Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 268 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get the caller's IP address in a WebMethod?

#1
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
Reply

#2
[HttpContext.Current.Request.UserHostAddress](

[To see links please register here]

) is what you want.
Reply

#3
The HttpContext is actually available inside the `WebService` base class, so just use `Context.Request` (or `HttpContext.Current` which also points to the current context) to get access to the members provided by the `HttpRequest`.
Reply

#4
Try this:

string ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Haven't tried it in a webMethod, but I use it in standard HttpRequests
Reply

#5
Try:

Context.Request.UserHostAddress



Reply

#6
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.
Reply

#7
I made the following function:

static public string sGetIP()
{
try
{
string functionReturnValue = null;

String oRequestHttp =
WebOperationContext.Current.IncomingRequest.Headers["User-Host-Address"];
if (string.IsNullOrEmpty(oRequestHttp))
{
OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint =
prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
oRequestHttp = endpoint.Address;
}
return functionReturnValue;
}
catch (Exception ex)
{
return "unknown IP";
}
}

This work only in Intranet, if you have some Proxy or natting you should study if the original IP is moved somewhere else in the http packet.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through