skip to Main Content

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


  1. You can get the IPv6 address in the current context with this:

    string IPv6 = HttpContext.Current.Request.UserHostAddress;
    
    Login or Signup to reply.
  2. 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"].

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search