I'm doing one project in Web API, So I want to get the client domain name or client IP Address which is trying to call my Web API. Is there any way to get the same. I'm waiting for your valuable response.
Asked
Active
Viewed 1,072 times
2 Answers
1
HttpContext.Request.Headers.Origin
The above will get you the domain name. For IP address, this post should give you the details.
Domain name is included with each request lands on your server.
If you open network tab in devtools of your browser (chrome for example) check request headers, and you will find the key-value
origin
scheme://sub.domain.extension
as in https://mail.google.com
. In Asp.Net Core
you can find it in HttpContext.Request.Headers.Origin
as an object property.
HttpContext.Request.Headers
it self is a key-value-pair
dictionary, as such, you can access the origin header, or any other header for that matter, using HttpContext.Request.Headers["origin"]
.

mhDuke
- 137
- 1
- 10
0
You can get the IPv6 address in the current context with this:
string IPv6 = HttpContext.Current.Request.UserHostAddress;

ExplodatedFaces
- 348
- 2
- 8
-
Thank you, but, If I use like this I'm getting value like this **::1** only, but I want proper domain name. How to get that? – Edwin K Biju Mar 26 '22 at 06:22
-
Hey this is extremely late but ::1 is a proper IP address. This is the IPv6 address for localhost. – ExplodatedFaces Jan 25 '23 at 12:40