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.
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.
2
Answers
You can get the IPv6 address in the current context with this:
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 inhttps://mail.google.com
. InAsp.Net Core
you can find it inHttpContext.Request.Headers.Origin
as an object property.HttpContext.Request.Headers
it self is akey-value-pair
dictionary, as such, you can access the origin header, or any other header for that matter, usingHttpContext.Request.Headers["origin"]
.