0

I have a ASP.NET WEB API Code that accepts few parameters. Inside the WEB API code, I am using HttpContext.Current.Request.UserHostAddress to fetch the Request's IP Address; I have another ASP.NET Website deployed on some other server (Server = \x152), this website is having the AJAX code to call the Web API. Now I am using my local machine to make a request to the website (on Server \x152) that in-turn can call the WEB API through the AJAX CAll written in the code. I want to get the IP address of Server \x152 in my WEB API code, but everytime it is fetching the IP address of my local machine. How to fetch the IP address of the Server \x152?

Luvkush
  • 13
  • 3
  • Hi Luvkush, I am also looking for same solution. Did you achieve this one. Please let me know, it will be very helpful for me. I have deployed my application in Azure APP service – Roushan May 21 '20 at 13:04

1 Answers1

-1

You may check this answer. It depends how is your application is hosted.

For web hosted version

    string clientAddress = HttpContext.Current.Request.UserHostAddress;

For self hosted

    object property;
    Request.Properties.TryGetValue(typeof(RemoteEndpointMessageProperty).FullName, out property);

    RemoteEndpointMessageProperty remoteProperty = property as RemoteEndpointMessageProperty;
Community
  • 1
  • 1
riteshmeher
  • 854
  • 8
  • 16
  • string clientAddress = HttpContext.Current.Request.UserHostAddress; This code always giving the ISP IP address. – Roushan May 21 '20 at 13:05