Back to Blog
Jan 25, 2023

Solving issues with https and SSL: .NET 6, Azure App Services, Cloudflare reverse proxy

Written by Zack Schwartz

Introduction

As fans of Azure App Services, we can attest to its convenience as a Platform-as-a-Service (PaaS) solution for deploying .NET applications. The Raytha platform, for instance, runs exceptionally well on Azure App Services for both .NET runtime and Azure Web App for Containers. At the time of this writing, we are currently utilizing Azure App Services for our platform. However, we recently encountered an issue with SSL and HTTPS after deploying the application behind a Cloudflare reverse proxy. We rely on Cloudflare for SSL and direct traffic to the Azure App Service. The problem we faced is that the .NET application running on Azure App Services seemed to be unaware that it is running behind HTTPS, resulting in URLs generated from the platform being displayed as "http://" instead of "https://".

The fix

After much research and troubleshooting, we discovered a helpful article hidden deep within the learn.microsoft.com documentation website. If you are running your .NET application on Azure App Services behind a reverse proxy such as Cloudflare, that handles all SSL requirements, you can easily resolve this issue by navigating to the Configuration panel in your Azure App Services and adding an Application Setting for:

ASPNETCORE_FORWARDEDHEADERS_ENABLED: true

The root cause of the problem lies in the way Azure App Services processes incoming traffic. By implementing the specified environment variable, we were able to instruct Azure App Services to trust the traffic coming from the reverse proxy and forward the headers associated with the request, including the crucial X-FORWARDED-PROTO header. This header is what the .NET application uses to determine the protocol of the incoming request, whether it be HTTP or HTTPS.

With this simple change, we were able to resolve the issue and restore proper functionality to our application. We hope that this information proves helpful for others who may encounter a similar problem.

picture of the author
Zack Schwartz @apexdodge

ENTREPRENEUR & SOFTWARE ENGINEER, AUSTIN, TX
I enjoy tackling a wide array of business challenges ranging from front line product support and operations to sales and marketing efforts. My core expertise is in software development building enterprise level web applications.


Subscribe to the Raytha newsletter