Last active
January 19, 2022 18:20
-
-
Save jincod/5d1cec864da231f60611daf20a9ac75f to your computer and use it in GitHub Desktop.
Ensure https for ASP.NET Core apps on Heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsProduction()) | |
{ | |
app | |
.UseForwardedHeaders() | |
.UseHttpsRedirection(); | |
} | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
// ... | |
services.AddHttpsRedirection(options => { options.HttpsPort = 443; }); | |
services.Configure<ForwardedHeadersOptions>(options => | |
{ | |
options.KnownNetworks.Clear(); | |
options.KnownProxies.Clear(); | |
options.ForwardedHeaders = | |
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; | |
}); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment