how to get a client IP address in ASP.NET 3.1 when writing code in Web API project
Asked
Active
Viewed 1.7k times
8
-
1Does this answer your question? [Asp Net Web API 2.1 get client IP address](https://stackoverflow.com/questions/22532806/asp-net-web-api-2-1-get-client-ip-address) – Kiya Jan 13 '20 at 06:55
-
Does this answer your question? [How do I get client IP address in ASP.NET CORE?](https://stackoverflow.com/questions/28664686/how-do-i-get-client-ip-address-in-asp-net-core) – Sayyed Dawood Nov 01 '21 at 05:47
2 Answers
11
Use this tutorial. wish it will help you. Get client IP address in Asp.NET core 3
Or just use this line of code in your controller:
var ip =HttpContext.Connection.RemoteIpAddress.ToString()

elahe karami
- 641
- 5
- 11