diff --git a/build/templates/UmbracoProject/.template.config/dotnetcli.host.json b/build/templates/UmbracoProject/.template.config/dotnetcli.host.json
index d0548110fd..d357188ed7 100644
--- a/build/templates/UmbracoProject/.template.config/dotnetcli.host.json
+++ b/build/templates/UmbracoProject/.template.config/dotnetcli.host.json
@@ -32,6 +32,10 @@
"NoNodesViewPath":{
"longName": "no-nodes-view-path",
"shortName": ""
+ },
+ "UseHttpsRedirect": {
+ "longName": "use-https-redirect",
+ "shortName": ""
}
},
"usageExamples": [
diff --git a/build/templates/UmbracoProject/.template.config/ide.host.json b/build/templates/UmbracoProject/.template.config/ide.host.json
index 8b8d2608cd..1ee7a492aa 100644
--- a/build/templates/UmbracoProject/.template.config/ide.host.json
+++ b/build/templates/UmbracoProject/.template.config/ide.host.json
@@ -62,6 +62,13 @@
"text": "Optional: Path to a custom view presented with the Umbraco installation contains no published content"
},
"isVisible": "true"
+ },
+ {
+ "id": "UseHttpsRedirect",
+ "name": {
+ "text": "Optional: Adds code to Startup.cs to redirect HTTP to HTTPS and enables the UseHttps setting."
+ },
+ "isVisible": "true"
}
]
}
diff --git a/build/templates/UmbracoProject/.template.config/template.json b/build/templates/UmbracoProject/.template.config/template.json
index 3d4f197164..3cf7485ab2 100644
--- a/build/templates/UmbracoProject/.template.config/template.json
+++ b/build/templates/UmbracoProject/.template.config/template.json
@@ -293,6 +293,12 @@
"UsingUnattenedInstall":{
"type": "computed",
"value": "(FriendlyName != \"\" && Email != \"\" && Password != \"\" && ConnectionString != \"\")"
+ },
+ "UseHttpsRedirect":{
+ "type": "parameter",
+ "datatype":"bool",
+ "defaultValue": "false",
+ "description": "Adds code to Startup.cs to redirect HTTP to HTTPS and enables the UseHttps setting (Default: false)"
}
}
}
diff --git a/build/templates/UmbracoProject/appsettings.json b/build/templates/UmbracoProject/appsettings.json
index 915671ce4b..feb6b07d95 100644
--- a/build/templates/UmbracoProject/appsettings.json
+++ b/build/templates/UmbracoProject/appsettings.json
@@ -15,9 +15,16 @@
},
"Umbraco": {
"CMS": {
- //#if (HasNoNodesViewPath)
+ //#if (HasNoNodesViewPath || UseHttpsRedirect)
"Global": {
+ //#if (!HasNoNodesViewPath && UseHttpsRedirect)
+ "UseHttps": true
+ //#elseif (UseHttpsRedirect)
+ "UseHttps": true,
+ //#endif
+ //#if (HasNoNodesViewPath)
"NoNodesViewPath": "NO_NODES_VIEW_PATH_FROM_TEMPLATE"
+ //#endif
},
//#endif
"Hosting": {
diff --git a/src/Umbraco.Web.UI/Startup.cs b/src/Umbraco.Web.UI/Startup.cs
index 0d263c7b6b..71c3dd008c 100644
--- a/src/Umbraco.Web.UI/Startup.cs
+++ b/src/Umbraco.Web.UI/Startup.cs
@@ -15,10 +15,10 @@ namespace Umbraco.Cms.Web.UI
private readonly IConfiguration _config;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- /// The Web Host Environment
- /// The Configuration
+ /// The web hosting environment.
+ /// The configuration.
///
/// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337
///
@@ -28,11 +28,10 @@ namespace Umbraco.Cms.Web.UI
_config = config ?? throw new ArgumentNullException(nameof(config));
}
-
-
///
- /// Configures the services
+ /// Configures the services.
///
+ /// The services.
///
/// This method gets called by the runtime. Use this method to add services to the container.
/// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
@@ -50,8 +49,10 @@ namespace Umbraco.Cms.Web.UI
}
///
- /// Configures the application
+ /// Configures the application.
///
+ /// The application builder.
+ /// The web hosting environment.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
@@ -59,6 +60,10 @@ namespace Umbraco.Cms.Web.UI
app.UseDeveloperExceptionPage();
}
+#if (UseHttpsRedirect)
+ app.UseHttpsRedirection();
+
+#endif
app.UseUmbraco()
.WithMiddleware(u =>
{