Use HTTP files locally and on the server
I am working on an ASP.NET Core project using HTTPS, so I have at startup:
// In Configure method
RewriteOptions rewriteOptions = new RewriteOptions();
rewriteOptions.AddRedirectToHttps();
// In ConfigureServices method
services.AddMvc(x => {
x.Filters.Add(new RequireHttpsAttribute());
});
Then, in the Program class, I have the following:
IWebHostBuilder builder = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
builder.UseKestrel(x => {
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (env == "Development"))
x.UseHttps(@"../../local.pfx", "Password");
});
IWebHost host = builder.Build();
host.Run();
I am checking if the environment is development to use a local certificate.
Otherwise, it will use the certificate on the server (Azure in this case).
This works both locally and in Azure.
But should it be done this way?
+3
source to share
No one has answered this question yet
Check out similar questions: