From 4cad48585934d81b105199719b889a57cf3cd0cf Mon Sep 17 00:00:00 2001 From: Scott Addie <10702007+scottaddie@users.noreply.github.com> Date: Fri, 6 Sep 2019 15:51:22 -0500 Subject: [PATCH] Add https_port setting to appsettings.json (#14188) --- aspnetcore/security/enforcing-ssl.md | 10 +++---- .../sample-snapshot/2.x/Program.cs | 20 ------------- .../sample-snapshot/2.x/appsettings.json | 9 ++++++ .../sample-snapshot/3.x/Program.cs | 30 ------------------- .../sample-snapshot/3.x/appsettings.json | 11 +++++++ 5 files changed, 25 insertions(+), 55 deletions(-) delete mode 100644 aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/Program.cs create mode 100644 aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/appsettings.json delete mode 100644 aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/Program.cs create mode 100644 aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/appsettings.json diff --git a/aspnetcore/security/enforcing-ssl.md b/aspnetcore/security/enforcing-ssl.md index 1e0e0706c4..0fbee33658 100644 --- a/aspnetcore/security/enforcing-ssl.md +++ b/aspnetcore/security/enforcing-ssl.md @@ -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 . 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 . This approach doesn't work in reverse proxy deployments. diff --git a/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/Program.cs b/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/Program.cs deleted file mode 100644 index 2fd54344de..0000000000 --- a/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/Program.cs +++ /dev/null @@ -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(); - } - #endregion -} diff --git a/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/appsettings.json b/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/appsettings.json new file mode 100644 index 0000000000..48f2aa6d04 --- /dev/null +++ b/aspnetcore/security/enforcing-ssl/sample-snapshot/2.x/appsettings.json @@ -0,0 +1,9 @@ +{ + "https_port": 443, + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/Program.cs b/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/Program.cs deleted file mode 100644 index 67073cc69e..0000000000 --- a/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/Program.cs +++ /dev/null @@ -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(); - }); - } - #endregion -} - diff --git a/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/appsettings.json b/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/appsettings.json new file mode 100644 index 0000000000..491691f570 --- /dev/null +++ b/aspnetcore/security/enforcing-ssl/sample-snapshot/3.x/appsettings.json @@ -0,0 +1,11 @@ +{ + "https_port": 443, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file