Skip to content

Fix: Apply HTTPS redirection in non-Development environments#1145

Open
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/https-redirection-fix
Open

Fix: Apply HTTPS redirection in non-Development environments#1145
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/https-redirection-fix

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

Problem

HTTPS redirection middleware was only applied in Development environments due to an inverted conditional check. This allowed HTTP requests to be served in Production and Staging, defeating the purpose of enforcing HTTPS for security.

Solution

Inverted the environment check in Program.cs so UseHttpsRedirection() now runs in non-Development environments (Production/Staging) instead of only in Development.

Changes

  • Modified Program.cs line 551: changed if (app.Environment.IsDevelopment()) to if (!app.Environment.IsDevelopment())
  • This ensures HTTPS redirection is properly applied in production deployments

Testing

  • Build verified: solution compiles without errors or warnings
  • Syntax and logic are correct and ready for deployment

- Inverted the IsDevelopment() check so UseHttpsRedirection middleware runs in Production/Staging
- Previously middleware was only applied in Development, which is backwards
- Now correctly enforces HTTPS in production deployments
Copilot AI review requested due to automatic review settings May 20, 2026 04:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the ASP.NET Core middleware pipeline so HTTPS redirection is enforced outside Development, aligning production/staging behavior with the app’s security goals.

Changes:

  • Inverted the environment check so UseHttpsRedirection() runs in non-Development environments.
  • Preserves existing Development behavior (no HTTPS redirection applied).

Comment thread EssentialCSharp.Web/Program.cs
- Add AddHttpsRedirection() service configuration with HttpsPort = 443
- Ensures middleware reliably enforces HTTPS redirects in production behind TLS-terminating proxy
- Prevents silent failure of HTTPS redirection when port cannot be auto-detected
- Positioned after AddTrustedForwardedHeaders() to group proxy-related configurations
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants