Add https_port setting to appsettings.json (#14188)

pull/14199/head
Scott Addie 2019-09-06 15:51:22 -05:00 committed by GitHub
parent 188400b0f0
commit 4cad485859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 55 deletions

View File

@ -4,7 +4,7 @@ author: rick-anderson
description: Learn how to require HTTPS/TLS in a ASP.NET Core web app.
ms.author: riande
ms.custom: mvc
ms.date: 12/01/2018
ms.date: 09/06/2019
uid: security/enforcing-ssl
---
# Enforce HTTPS in ASP.NET Core
@ -96,9 +96,9 @@ Specify the HTTPS port using any of the following approaches:
* In host configuration.
* By setting the `ASPNETCORE_HTTPS_PORT` environment variable.
* By calling `UseSetting`:
* By adding a top-level entry in *appsettings.json*:
[!code-csharp[](enforcing-ssl/sample-snapshot/3.x/Program.cs?name=snippet_Program&highlight=12)]
[!code-json[](enforcing-ssl/sample-snapshot/3.x/appsettings.json?highlight=2)]
* Indicate a port with the secure scheme using the [ASPNETCORE_URLS environment variable](/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.0#urls). The environment variable configures the server. The middleware indirectly discovers the HTTPS port via <xref:Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature>. This approach doesn't work in reverse proxy deployments.
@ -110,9 +110,9 @@ Specify the HTTPS port using any of the following approaches:
* In host configuration.
* By setting the `ASPNETCORE_HTTPS_PORT` environment variable.
* By calling `UseSetting`:
* By adding a top-level entry in *appsettings.json*:
[!code-csharp[](enforcing-ssl/sample-snapshot/2.x/Program.cs?name=snippet_Program&highlight=10)]
[!code-json[](enforcing-ssl/sample-snapshot/2.x/appsettings.json?highlight=2)]
* Indicate a port with the secure scheme using the [ASPNETCORE_URLS environment variable](xref:fundamentals/host/web-host#server-urls). The environment variable configures the server. The middleware indirectly discovers the HTTPS port via <xref:Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature>. This approach doesn't work in reverse proxy deployments.

View File

@ -1,20 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace EnvironmentsSample
{
#region snippet_Program
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSetting("https_port", "8080")
.UseStartup<Startup>();
}
#endregion
}

View File

@ -0,0 +1,9 @@
{
"https_port": 443,
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace WebHTTPS
{
#region snippet_Program
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseSetting("https_port", "8080")
.UseStartup<Startup>();
});
}
#endregion
}

View File

@ -0,0 +1,11 @@
{
"https_port": 443,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}