Skip to content

Commit 9c0c41d

Browse files
Merge pull request #363 from GeekInTheNorth/feature/multi-site-support
Add multi-site support to the CMS 13 solution
2 parents 1d0c861 + 86b932c commit 9c0c41d

150 files changed

Lines changed: 5403 additions & 1799 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,7 @@ MigrationBackup/
362362
.vscode/
363363

364364
# AI
365-
.claude/
365+
.claude/
366+
367+
# Settings
368+
appsettings.Development.json

Sample/OptimizelyTwelveTest/Features/Configuration/SetupMigrationStep.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,50 @@ public override void AddChanges()
2222
{
2323
try
2424
{
25-
SetUpSystem();
25+
var appRepository = ServiceLocator.Current.GetInstance<IApplicationRepository>();
26+
if (!ConfigurationExists(appRepository))
27+
{
28+
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
29+
SetUpSystem(appRepository, contentRepository, 1, 5000, 5001);
30+
SetUpSystem(appRepository, contentRepository, 2, 5002, 5003);
31+
}
2632
}
2733
catch(Exception ex)
2834
{
2935
Console.WriteLine($"Error encountered during initial configuration: {ex.Message}");
3036
}
3137
}
3238

33-
private void SetUpSystem()
39+
private static bool ConfigurationExists(IApplicationRepository appRepository)
3440
{
35-
var appRepository = ServiceLocator.Current.GetInstance<IApplicationRepository>();
3641
var sites = appRepository.List();
37-
if (sites.Any())
38-
{
39-
return;
40-
}
42+
return sites.Any();
43+
}
4144

42-
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
45+
private static void SetUpSystem(IApplicationRepository appRepository, IContentRepository contentRepository, int siteNumber, int portOne, int portTwo)
46+
{
4347
var culture = new CultureInfo("en");
4448

4549
// Create HomePage
4650
var newHomePage = contentRepository.GetDefault<HomePage>(ContentReference.RootPage, culture);
47-
newHomePage.Name = "Home";
48-
newHomePage.Heading = "Home";
49-
newHomePage.MetaTitle = "Home";
51+
newHomePage.Name = $"Home {siteNumber}";
52+
newHomePage.Heading = $"Home {siteNumber}";
53+
newHomePage.MetaTitle = $"Home {siteNumber}";
5054

5155
var homePageReference = contentRepository.Save(newHomePage, SaveAction.Publish, AccessLevel.NoAccess);
5256

5357
// Create Not Found Page
54-
var newNotFoundPage = contentRepository.GetDefault<NotFoundPage>(ContentReference.RootPage, culture);
55-
newNotFoundPage.Name = "Not Found";
56-
newNotFoundPage.MetaTitle = "Home";
58+
var newNotFoundPage = contentRepository.GetDefault<NotFoundPage>(homePageReference, culture);
59+
newNotFoundPage.Name = $"Not Found {siteNumber}";
60+
newNotFoundPage.MetaTitle = $"Not Found {siteNumber}";
5761

5862
var notFoundReference = contentRepository.Save(newNotFoundPage, SaveAction.Publish, AccessLevel.NoAccess);
5963

6064
// Create SiteSettings
6165
var newSiteSettings = contentRepository.GetDefault<SiteSettingsPage>(homePageReference, culture);
62-
newSiteSettings.Name = "[Site Settings]";
66+
newSiteSettings.Name = $"[Site Settings {siteNumber}]";
6367
newSiteSettings.NotFoundPage = notFoundReference.ToReferenceWithoutVersion();
64-
newSiteSettings.SiteName = "Stott Security Dev Site";
68+
newSiteSettings.SiteName = $"Site {siteNumber}";
6569

6670
var siteSettingsReference = contentRepository.Save(newSiteSettings, SaveAction.Publish, AccessLevel.NoAccess);
6771

@@ -73,17 +77,23 @@ private void SetUpSystem()
7377
homePageReference = contentRepository.Save(editableHomePage, SaveAction.Publish, AccessLevel.NoAccess);
7478

7579
// Create Site
76-
var newSite = new Website("TestWebsite", homePageReference.ToReferenceWithoutVersion())
80+
var newSite = new Website($"TestWebsite{siteNumber}", homePageReference.ToReferenceWithoutVersion())
7781
{
78-
DisplayName = "Test Website"
82+
DisplayName = $"Test Website {siteNumber}"
7983
};
8084

81-
newSite.Hosts.Add(new ApplicationHost("localhost:44344")
85+
newSite.Hosts.Add(new ApplicationHost($"localhost:{portOne}")
8286
{
8387
UseSecureConnection = true,
8488
Type = ApplicationHostType.Primary
8589
});
86-
90+
91+
newSite.Hosts.Add(new ApplicationHost($"localhost:{portTwo}")
92+
{
93+
UseSecureConnection = true,
94+
Type = ApplicationHostType.Edit
95+
});
96+
8797
appRepository.SaveAsync(newSite).GetAwaiter().GetResult();
8898
}
8999
}

Sample/OptimizelyTwelveTest/Features/Home/HomePageController.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99

1010
using Stott.Security.Optimizely.Features.Csp.Settings.Service;
1111

12-
public class HomePageController : PageControllerBase<HomePage>
12+
public class HomePageController(ICspSettingsService cspSettingsService) : PageControllerBase<HomePage>
1313
{
14-
private readonly ICspSettingsService _cspSettingsService;
15-
16-
public HomePageController(ICspSettingsService cspSettingsService)
17-
{
18-
_cspSettingsService = cspSettingsService;
19-
}
14+
private readonly ICspSettingsService _cspSettingsService = cspSettingsService;
2015

2116
[SecurityHeaderAction]
2217
public async Task<IActionResult> Index(HomePage currentPage, bool resetReportMode)
@@ -25,9 +20,9 @@ public async Task<IActionResult> Index(HomePage currentPage, bool resetReportMod
2520

2621
if (resetReportMode)
2722
{
28-
var currentSettings = await _cspSettingsService.GetAsync();
23+
var currentSettings = await _cspSettingsService.GetAsync(null, null);
2924
currentSettings.IsReportOnly = true;
30-
await _cspSettingsService.SaveAsync(currentSettings, "Mark Stott");
25+
await _cspSettingsService.SaveAsync(currentSettings, "Mark Stott", null, null);
3126
}
3227

3328
return View(model);
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
namespace OptimizelyTwelveTest;
22

3+
using System;
4+
35
using Microsoft.AspNetCore.Hosting;
46
using Microsoft.Extensions.Hosting;
57

6-
using System;
7-
88
public class Program
99
{
10-
public static void Main(string[] args)
10+
public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();
11+
12+
public static IHostBuilder CreateHostBuilder(string[] args)
1113
{
1214
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
13-
var isDevelopment = environment == Environments.Development;
14-
15-
if (isDevelopment)
16-
{
17-
//Development configuration
18-
}
19-
20-
CreateHostBuilder(args, isDevelopment).Build().Run();
21-
}
2215

23-
public static IHostBuilder CreateHostBuilder(string[] args, bool isDevelopment)
24-
{
25-
if (isDevelopment)
16+
if (environment == Environments.Development)
2617
{
27-
//Development configuration can be addded here, like local logging.
2818
return Host.CreateDefaultBuilder(args)
29-
.ConfigureCmsDefaults()
30-
.ConfigureWebHostDefaults(webBuilder =>
31-
{
32-
webBuilder.UseStartup<Startup>();
33-
});
19+
.ConfigureCmsDefaults()
20+
.ConfigureWebHostDefaults(webBuilder => webBuilder.ConfigureKestrel((context, options) =>
21+
{
22+
// Add valid HTTPS ports for development that are compatible with Opti Id
23+
options.ListenLocalhost(5000, options => { options.UseHttps(); });
24+
options.ListenLocalhost(5001, options => { options.UseHttps(); });
25+
options.ListenLocalhost(5002, options => { options.UseHttps(); });
26+
options.ListenLocalhost(5003, options => { options.UseHttps(); });
27+
28+
options.Limits.MaxRequestBodySize = 2147483648;
29+
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(60);
30+
})
31+
.UseStartup<Startup>());
3432
}
3533
else
3634
{
3735
return Host.CreateDefaultBuilder(args)
38-
.ConfigureCmsDefaults()
39-
.ConfigureWebHostDefaults(webBuilder =>
40-
{
41-
webBuilder.UseStartup<Startup>();
42-
});
36+
.ConfigureCmsDefaults()
37+
.ConfigureWebHostDefaults(webBuilder => webBuilder.ConfigureKestrel((context, options) =>
38+
{
39+
options.Limits.MaxRequestBodySize = 2147483648;
40+
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(60);
41+
})
42+
.UseStartup<Startup>());
4343
}
4444
}
45-
}
45+
}
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "http://localhost:60396/",
7-
"sslPort": 44344
8-
}
9-
},
102
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"launchBrowser": true,
14-
"environmentVariables": {
15-
"ASPNETCORE_ENVIRONMENT": "Development"
16-
}
17-
},
183
"OptimizelyTwelveTest": {
194
"commandName": "Project",
205
"launchBrowser": true,
216
"environmentVariables": {
227
"ASPNETCORE_ENVIRONMENT": "Development"
238
},
24-
"applicationUrl": "https://localhost:5001;http://localhost:5000"
9+
"applicationUrl": "https://localhost:5000"
2510
}
2611
}
2712
}

Sample/OptimizelyTwelveTest/appsettings.Development.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sample/OptimizelyTwelveTest/appsettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"Microsoft.Hosting.Lifetime": "Warning"
88
}
99
},
10-
"urls": "http://*:8000/;https://*:8001/;",
1110
"AllowedHosts": "*",
1211
"ConnectionStrings": {
1312
"EPiServerDB": "Server=(localdb)\\mssqllocaldb;Database=StottSecurityCms13Db;Trusted_Connection=true;MultipleActiveResultSets=true"

0 commit comments

Comments
 (0)