IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| JIT-Compilation :👈 | 👉:Reverse Proxy |
Proxy Server |
A Proxy Server is an intermediate server that sits between a client (browser, application, or user) and another server on the internet or network.
Instead of the client communicating directly with the destination server, the request first goes to the proxy server, and the proxy forwards the request on behalf of the client.
💻 Client ---> 🖥️ Proxy Server ---> 🌐 Web Server
🔄 Request Forwarded
We need a proxy server primarily to act as a secure, controlled intermediary between an internal network and the internet.
Depending on your architecture, a proxy is used for the following core reasons:
Suppose a .NET application needs to call an external API:
💻 .NET Application ---> 🖥️ Proxy Server ---> 🌐 [https://api.example.com](https://api.example.com)
The external API sees the proxy server's IP instead of the application's IP.
Using HttpClient with a proxy server:
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var proxy = new WebProxy("[http://192.168.1.100:8080](http://192.168.1.100:8080)");
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
using var client = new HttpClient(handler);
var response = await client.GetAsync("[https://api.github.com](https://api.github.com)");
Console.WriteLine(response.StatusCode);
}
}
WebProxy specifies the proxy server address.HttpClientHandler tells HttpClient to use the proxy.Consider a company network:
💻 Employee PC ---> 🖥️ Corporate Proxy Server ---> 🌐 google.com
When an employee opens Google:
This allows the company to:
Use a proxy when it provides a clear business, security, or networking benefit.
A company wants to control employee internet usage.
💻 Employee PC ---> 🖥️ Proxy Server ---> 🌐 Internet
Benefits:
Many payment gateways, banking APIs, and partner systems allow requests only from known IP addresses.
💻 .NET App ---> 🖥️ Proxy Server (Fixed IP) ---> 🌐 Partner API
Use a proxy when:
👥 Users ---> 🗄️ Caching Proxy ---> 🌐 Website
Benefits:
A proxy can hide internal machine IP addresses.
🏢 Internal Network ---> 🖥️ Proxy ---> 🌐 External Service
Organizations often route traffic through a proxy to:
If your application only communicates within the same network:
💻 Web App ---> 🗄️ SQL Server
Adding a proxy generally provides no benefit and increases complexity.
Examples:
Every proxy introduces another network hop:
Client -> Proxy -> Server
This may increase latency.
If external APIs are directly accessible and security requirements don't mandate a proxy, avoid unnecessary infrastructure.
For a simple startup or internal tool:
💻 .NET App --> 🌐 API
A proxy may create:
Avoid hardcoding:
var proxy = new WebProxy("[http://192.168.1.100:8080](http://192.168.1.100:8080)");
Better:
{
"ProxyUrl": "[http://proxy.company.com:8080](http://proxy.company.com:8080)"
}
Read from:
builder.Configuration["ProxyUrl"];
HttpClientFactoryBad:
new HttpClient(); new HttpClient(); new HttpClient();
Good:
services.AddHttpClient();
This avoids socket exhaustion .
client.Timeout = TimeSpan.FromSeconds(30);
A proxy outage should not hang your application indefinitely.
try
{
var response = await client.GetAsync(url);
}
catch(HttpRequestException ex)
{
logger.LogError(ex, "Proxy communication failed");
}
var proxy = new WebProxy(proxyUrl)
{
Credentials = new NetworkCredential(
"username",
"password")
};
Avoid anonymous proxies in production.
Bad:
App -> HTTP Proxy -> API
Better:
App -> HTTPS Proxy -> HTTPS API
Encrypt traffic whenever possible.
Useful when troubleshooting:
logger.LogInformation(
"Using proxy: {ProxyUrl}",
proxyUrl);
Many companies maintain a bypass list:
var proxy = new WebProxy(proxyUrl)
{
BypassProxyOnLocal = true
};
Examples:
Use a Proxy when:
Avoid a Proxy when:
A common architecture is:
ASP.NET Core App ---> Corporate Proxy / API Gateway ---> External APIs
For small internal apps or public cloud services, a direct connection is usually simpler and easier to maintain.
| Proxy Server (Forward Proxy) | Reverse Proxy |
|---|---|
| Protects clients | Protects servers |
| Used by users/applications | Used by web servers |
| Hides client identity | Hides server identity |
| Example: Corporate proxy | Example: Nginx, IIS ARR |
Forward Proxy: Client → Proxy → Internet
Reverse Proxy: Internet → Reverse Proxy → Web Server
In .NET applications, proxy servers are commonly used when calling external APIs through corporate networks or secure gateways.
| JIT-Compilation :👈 | 👉:Reverse Proxy |