❔ Need help implementing CORS and IP-based access control in ASP.NET Core Web API
I'm currently working on an ASP.NET Core Web API project and I need assistance with implementing CORS (Cross-Origin Resource Sharing) and IP-based access control. Here's the scenario:
I have a requirement to allow access to the API only from devices whose IP addresses are registered in a database. If the IP address of the device making the request doesn't match any of the registered IP addresses, the content should not be accessible.
To achieve this, I'm planning to use custom middleware. I would greatly appreciate any guidance or code examples on how to accomplish this in ASP.NET Core. Specifically, I'm looking for help with:
Setting up CORS to allow cross-origin requests.
Retrieving the IP address of the device making the request.
Validating the IP address against the database records.
Blocking access if the IP address is not found in the database.
Any insights, best practices, or code snippets you can provide would be highly appreciated. Thank you in advance for your help!
I have a requirement to allow access to the API only from devices whose IP addresses are registered in a database. If the IP address of the device making the request doesn't match any of the registered IP addresses, the content should not be accessible.
To achieve this, I'm planning to use custom middleware. I would greatly appreciate any guidance or code examples on how to accomplish this in ASP.NET Core. Specifically, I'm looking for help with:
Setting up CORS to allow cross-origin requests.
Retrieving the IP address of the device making the request.
Validating the IP address against the database records.
Blocking access if the IP address is not found in the database.
Any insights, best practices, or code snippets you can provide would be highly appreciated. Thank you in advance for your help!
