---
title: Always Use TLS For All Connections
impact: HIGH
impactDescription: protects data in transit from eavesdropping
tags: tls, https, encryption, transport, security, csharp
---

## Always Use TLS For All Connections

Force HTTPS in your application and ensure all external connections use TLS.

**Incorrect (HTTP):**

```csharp
// Unencrypted HttpClient
var client = new HttpClient { BaseAddress = new Uri("http://api.example.com") };
```

**Correct (HTTPS Enforcement):**

```csharp
// Startup.cs / Program.cs
public void Configure(IApplicationBuilder app)
{
    // Force HTTPS Redirection
    app.UseHttpsRedirection();
    
    // HSTS (Strict Transport Security)
    app.UseHsts();
}

// Secure HttpClient
var client = new HttpClient { BaseAddress = new Uri("https://api.example.com") };
```

**Tools:** SSLyze, OWASP ZAP
