.NET Integration
Use this guide to integrate InstantProxies into .NET applications, services, workers, and request-driven automation workflows.
.NET is commonly used in backend services, internal platforms, scheduled jobs, and enterprise systems where reliability, maintainability, and environment-aware configuration matter. Proxy integration should be handled as reusable client infrastructure, not embedded into request code or business logic.
Use .NET when
.NET is a good fit when your workload depends on:
- backend services and APIs
- internal business systems and enterprise applications
- request-driven background jobs and automation tooling
- workloads where timeout behavior and environment handling should remain explicit
- systems that benefit from reusable client infrastructure and structured dependency management
If the workflow is fully browser-driven, use a browser automation guide instead. If you need a fast validation path before deeper integration, start with First Request with cURL.
Integration requirements
A production-ready .NET integration should be:
- predictable across local, staging, and production environments
- built around reusable client configuration
- easy to validate before larger workflow complexity is introduced
- compatible with timeout, retry, and logging strategies
- structured so transport behavior stays separate from business logic
- maintainable for long-lived services and team-owned systems
Treat proxy configuration as handler and client design
Do not scatter proxy settings across request code or ad hoc helpers.
Separate:
- client construction
- handler configuration
- proxy behavior
- timeout behavior
- environment-specific values
- logging and validation hooks
- request execution logic
This keeps transport behavior consistent and easier to debug.
Start with a minimal reusable client
Validate the transport path with a minimal reusable client before embedding it into service logic.
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var proxy = new WebProxy("http://YOUR_PROXY_HOST:PORT");
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
using var client = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(20)
};
var response = await client.GetAsync("https://httpbin.org/ip");
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(body);
}
}
Use this first to verify that:
- the client uses the intended proxy route
- the handler is configured correctly
- timeout behavior is visible
- one simple request completes successfully
If you have not yet proven the proxy path outside .NET, pair this page with Verify Your Connection.
Configure authentication correctly
InstantProxies supports:
- IP whitelisting or authorization
- username and password authentication
If IP whitelisting is active, authorize the public IP of the real runtime environment.
If username and password authentication is active, keep credentials in environment-aware configuration and attach them to the proxy definition intentionally.
using System;
using System.Net;
var host = Environment.GetEnvironmentVariable("INSTANTPROXIES_HOST");
var port = Environment.GetEnvironmentVariable("INSTANTPROXIES_PORT");
var username = Environment.GetEnvironmentVariable("INSTANTPROXIES_USERNAME");
var password = Environment.GetEnvironmentVariable("INSTANTPROXIES_PASSWORD");
var proxy = new WebProxy($"http://{host}:{port}")
{
Credentials = new NetworkCredential(username, password)
};
Do not hardcode credentials.
If authentication fails, see Authentication and Allowlist Errors.
Prefer reusable client infrastructure over ad hoc request code
Do not rebuild transport behavior close to request execution unless the workflow requires it.
Reusable client infrastructure improves:
- consistency across requests
- readability of the codebase
- shared timeout and logging behavior
- environment-aware configuration handling
- maintainability across services and teams
This is one reason proxy-backed behavior should usually be configured centrally rather than repeated at individual call sites.
Keep client setup separate from request logic
Request handlers and service logic should use a configured client. They should not rebuild proxy settings, handlers, or timeouts inline.
Centralize:
HttpClientHandlercreation- proxy settings
- timeout values
- environment-specific configuration
- validation helpers
- logging hooks
This keeps runtime behavior consistent across the codebase.
Validate in stages
Validate in this order:
- one clean proxied request
- repeated execution of the same request
- timeout behavior
- reusable client construction
- structured logging
- retries or resilience policies
- broader workflow behavior and higher request volume
Do not start with full service flow or retry-heavy logic.
Make timeouts explicit
Timeout behavior should be configured deliberately.
Timeouts affect:
- how quickly failures surface
- whether degraded conditions are visible or hidden
- how retries behave later
- how easy it is to classify failures accurately
Set timeout behavior explicitly in the client. Do not rely on vague defaults for production workloads.
If timeout design needs deeper review, see Timeout Strategy.
Reuse clients intentionally
A .NET proxy integration is usually stronger when the client is reused rather than rebuilt at each call site.
Client reuse affects:
- consistency across requests
- maintainability of transport behavior
- repeated request behavior over time
- how easy it is to apply shared timeout, logging, and validation rules
Client construction should normally be centralized.
Add retries only after validating the base path
Retries can help, but only after the base request path is understood.
Premature retries often:
- hide client or authentication problems
- amplify already slow request paths
- make logs and metrics harder to interpret
- increase activity without improving useful throughput
Validate the transport path first. Then add retries or resilience policies only where recovery assumptions are realistic and observable.
If retry behavior needs deeper review, see Retry Strategy and Failure Recovery.
Log client-level signals
Log enough information to answer:
- which client and handler configuration was used
- what timeout assumptions applied
- whether the request followed the intended proxy path
- whether the visible issue looks local, proxy-related, or target-side
- whether environment differences changed the behavior
Use structured logging where possible.
For deeper guidance, see Logging and Diagnostic Signals.
Environment consistency matters
.NET applications often move across:
- local development
- CI pipelines
- containers
- staging
- production services
Keep proxy-backed behavior environment-aware. A one-time success in one runtime is not enough evidence for broader confidence.
Common failure patterns
Typical issues include:
- building clients too close to business logic
- leaving timeout behavior vague or inconsistent
- validating only one request path and assuming broader stability
- adding retries before the base transport behavior is understood
- weak separation between environment-specific values and code
- treating one successful response as evidence that the service is ready for production behavior
Recommended integration pattern
Use this sequence:
- define proxy and authentication settings in environment-aware configuration
- build one reusable handler
- build one reusable client
- validate one request path
- repeat the same path from the same environment
- make timeouts explicit
- add structured logging
- add retries and broader workflow behavior only after repeated execution is stable
Key points
- model proxy behavior through reusable client and handler configuration
- keep client setup separate from request and business logic
- validate repeated runs, not just one successful request
- make timeouts, logging, and authentication explicit
- reuse clients intentionally
- add retries only after the base path is understood
Next step
If the integration works but behaves inconsistently across environments or under repeated execution, continue to Debugging Integration Issues.
If the next concern is broader workload stability, continue to Reliability.