In C#/.NET Core
How to get user MetaData from user requests on API, Just like IP Address, Location, Lattitute Laongitute, Regin, Country, State, Url Reffer, etc
Home / DeveloperSection / Forums / How to get user MetaData from user request on API?
In C#/.NET Core
How to get user MetaData from user requests on API, Just like IP Address, Location, Lattitute Laongitute, Regin, Country, State, Url Reffer, etc
Anubhav Kumar
16-Dec-2024In .NET Core, you can extract user metadata from the
HttpRequest
object in an API controller. Here’s how you can access various types of metadata:1. IP Address
To get the user's IP address:
2. User Agent
To get the user agent string from the request headers:
3. Request Headers
To access all headers:
4. Referrer URL
To get the URL of the page that referred the user:
5. Authorization Information
To get the
Authorization
header (e.g., JWT or Bearer tokens):6. Query Parameters
To get query parameters:
7. Custom Metadata in Headers
If your client sends custom metadata in the headers (e.g.,
X-Custom-Metadata
), you can access it like this:Example Controller
Here’s an example controller that gathers and returns metadata:
Notes
ForwardedHeaders
middleware for this:Thanks for reading.