Here is my program.cs file
*
* How to use the Block Preview https://github.com/rickbutterfield/BlockPreview
*/
using Umbraco.App_Code.Helpers;
using Umbraco.App_Code.Media;
using Umbraco.App_Code.Wcag;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Community.BlockPreview.Extensions;
using Umbraco.Community.PagespeedOptimizer.Extensions;
using Umbraco.App_Code.CORS;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IWebHostEnvironment _env = builder.Environment;
ConfigurationManager _config = builder.Configuration;
CorsStartup cors = new CorsStartup(_config);
cors.AddCorse(builder);
settings Settings = new settings();
string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Console.WriteLine("HostingEnvironmentName: '{0}'", environment);
builder.Configuration.AddJsonFile($"appsettings.{Environment.MachineName}.json", true, true);
builder.Configuration.AddJsonFile($"appsettings.{environment}.json", true, true);
builder.Configuration.AddEnvironmentVariables();
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddComposers()
/*
* Added By Darren Hunter
* Date:26-05-2026
* Added for Block Grid Preview
*/
.AddBlockPreview(options =>
{
options.BlockGrid = new()
{
Enabled = true,
ContentTypes = ["button",
"embdedVideo",
"embed",
"expandingBox",
"faqHeader",
"faqListBox",
"fileDownload",
"formSelect",
"galleryBlock",
"GridImage",
"GridImageWithLink",
"inpageModel",
"richText",
"statistic",
"headlineH1",
"headlineH2",
"headlineH3",
"headlineH4",
"headlineH5",
"headlineH6",
"footerFeatureBlock",
"mainBlock",
"blockWithImage",
"blockWithText",
"login",
"staticHero",
"homePageButtons",
"propertiesToBuy",
"homePageNewsDemo"
],
IgnoredContentTypes = [],
ViewLocations = [],
Stylesheets = []
};
options.BlockList = new()
{
Enabled = true,
ContentTypes = [
"/Views/Partials/blocklist/Components/helpSectionTopic",
"/Views/Partials/blocklist/Components/helpSectionCategory",
"/Views/Partials/blocklist/Components/staffMember"
],
IgnoredContentTypes = [],
ViewLocations = [],
Stylesheets = []
};
options.RichText = new()
{
Enabled = true,
ContentTypes = [],
IgnoredContentTypes = [],
ViewLocations = [],
Stylesheets = []
};
})
/*
* Added for WCAG
*/
.AddNotificationHandler<ContentPublishingNotification, saveNotificationHandler>()
.AddNotificationHandler<ContentSavingNotification, BlockGridNotificationHandler>()
/*
* Back to Original code!
*/
.Build();
WebApplication app = builder.Build();
cors.useCores(app);
builder.Services.AddResponseCaching();
/*
* Added By Darren Hunter
* Date:26-05-2026
* To add headers ect for securety!
*
* Update: 08-05-2026 - Moved back to the Web Config.
*/
//app.Use(async (context, next) =>
//{
// context.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
// context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
// await next();
//});
/*
* Added By Darren Hunter
* Date:26-05-2026
* See:https://github.com/dawoe/umbraco-pagespeed-optimization
*/
app.EnableResponseCompression();
await app.BootUmbracoAsync();
app.UseHttpsRedirection();
app.UseMiddleware<MediaMiddleware>();
// Prevent caching when filter query parameters are present
app.Use(async (context, next) =>
{
if (context.Request.QueryString.HasValue)
{
context.Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
context.Response.Headers.Append("Pragma", "no-cache");
context.Response.Headers.Append("Expires", "0");
}
await next();
});
app.UseUmbraco()
.WithMiddleware(u =>
{
u.UseBackOffice();
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});
await app.RunAsync();