ASP.NET Core Interview Question #88
What is UseHttpsRedirection()?
Middleware & Request Pipeline Mid-Level Intermediate
Quick Interview Answer
UseHttpsRedirection redirects incoming HTTP requests to HTTPS. It helps ensure clients use an encrypted connection when HTTPS is available.
Detailed Explanation
UseHttpsRedirection redirects incoming HTTP requests to HTTPS. It helps ensure clients use an encrypted connection when HTTPS is available.
The middleware normally returns a redirect response pointing to the HTTPS version of the requested URL. Production hosting must also be configured correctly so the application knows the appropriate HTTPS scheme and port.
HTTPS redirection is not a substitute for proper TLS certificate and reverse-proxy configuration.
Code Example
var app = builder.Build();
app.UseHttpsRedirection();
app.MapControllers();