Hello every one Any way to hide network cal API in .net core mvc.
Loading
Hello every one Any way to hide network cal API in .net core mvc.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sangeetha SPosted Jan 3, 2025, 5:04 AM
Hiding network call APIs in a .NET Core MVC application typically involves several strategies to protect sensitive information and improve security. Here are some approaches you can consider:
Environment Variables: Store sensitive information such as API keys and connection strings in environment variables instead of hard-coding them in your application. You can access these variables in your application using
IConfiguration.Configuration Files: Use
appsettings.jsonor other configuration files to store your API URLs and credentials. Make sure to mark sensitive information as "secret" when using user secrets in development.Backend Proxy: Instead of calling the API directly from the client-side (JavaScript), create a backend endpoint in your MVC application that acts as a proxy. The client makes a request to your backend, which then makes the API call. This way, the client never sees the actual API endpoint or credentials.
Authentication and Authorization: Implement authentication and authorization mechanisms to restrict access to your APIs. Use tokens (like JWT) for secure communication between your frontend and backend.
Rate Limiting and Monitoring: Consider implementing rate limiting on your API to prevent abuse and monitor for unusual activity.
Use HTTPS: Always use HTTPS for secure communication between your client and server, as well as between your server and any external APIs.
Obfuscation: While not a foolproof method, you could obfuscate parts of your code to make it harder for someone to understand the flow of API calls.
Jaish MathewsPosted Jan 3, 2025, 4:06 AM
Hiding API calls in .NET Core MVC can be achieved by ensuring that sensitive details, such as API keys or implementation logic, are not exposed to the client or public. Below are steps and best practices to achieve this:
1. Use a Backend Proxy
Instead of calling the API directly from the client-side JavaScript, route the API call through your .NET Core MVC backend.
HttpClientor similar backend service.Example:
2. Store API Keys Securely
Avoid hardcoding API keys in your source code. Instead, store them securely:
appsettings.json).Example (
appsettings.json):Access in Code:
3. Implement Authentication and Authorization
Ensure that only authorized users can access the API proxy endpoints:
[Authorize]attributes to restrict access.Example:
4. Limit Data Exposure
Only expose the data needed by the client. Filter or transform the data before returning it.
Example:
5. Hide API Endpoints in JavaScript
If your application requires API calls from JavaScript, avoid exposing sensitive API keys:
6. Rate Limiting and Throttling
Prevent abuse of your API proxy by implementing rate limiting or throttling:
7. Obfuscate API Call Patterns
These practices will help you effectively "hide" API calls while ensuring security and proper functionality in your .NET Core MVC application.
Jignesh KumarPosted Jan 2, 2025, 5:23 PM
Hello Saurabh,
You can achieve using below,
Instead of calling external APIs directly from the frontend, route all calls through your backend. This way: