I'm currently using MVC4 web API and for one of the calls I need to get the client's IP address. Here is my setup...
Client computers have no internet access, only access to our intranet
since I am making cross domain calls, I have to iframe a web server page into the client HTML page and post a message.
Once the web server receives the message, it makes an ajax call to the RESTful service and C# takes it from there...
So my current goal is the get the IP address of the client machine. After some research, I found this...
private string GetClientIp(HttpRequestMessage request)
{
if (request.Properties.ContainsKey("MS_HttpContext"))
{
return ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}
else if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
{
RemoteEndpointMessageProperty prop;
prop = (RemoteEndpointMessageProperty)this.Request.Properties[RemoteEndpointMessageProperty.Name];
return prop.Address;
}
else
{
return null;
}
Now I realize I'm not the smartest person, but what would I pass for the parameter of HTTPRequestMessage request?
private string GetClientIp(HttpRequestMessage request)
Is there an example of this? Is this possible? Or is there another approach I should take for this