Reputation: 306
is there also an environment variable to deactivate a SSL redirect like it is able to set other ASPNETCORE variables within a docker container? similar to these:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=<pass>
- ASPNETCORE_Kestrel__Certificates__Default__Path=/usr/<path>/aspnetapp.pfx
Thanks in advance.
Upvotes: 0
Views: 695
Reputation: 222
In ASP.NET Core HTTPS redirection is usually configured in code. In fact, it is a recommended way for doing this in production web apps.
So the easiest way to do activation/deactivation would probably be to tie this code to the type of environment you are building it in.
So, in the Configure
method of your Startup
class, you can do something like this:
if (env.IsDevelopment())
{
// Just don't.
}
else
{
app.UseHttpsRedirection();
app.UseHsts();
}
Otherwise, you could introduce your own variable and read its value during configuration:
var httpsRedirectEnabled =
Environment.GetEnvironmentVariable("ASPNETCORE_CUSTOM_HTTPS_REDIRECT") == "true";
if (httpsRedirectEnabled)
{
app.UseHttpsRedirection();
app.UseHsts();
}
Mind you, this is not the best way for string comparisson, but it'll work in a pinch.
Upvotes: 2