Files
Umbraco-CMS/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs
Bjarke Berg e46a248832 Merge remote-tracking branch 'origin/netcore/netcore' into netcore/task/6973-migrating-authenticationcontroller-merge
# Conflicts:
#	src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs
#	src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs
#	src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs
#	src/Umbraco.Infrastructure/Scheduling/SchedulerComposer.cs
#	src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs
#	src/Umbraco.Tests/Testing/UmbracoTestBase.cs
#	src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs
#	src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs
#	src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs
#	src/Umbraco.Web.Common/UmbracoContext/UmbracoContext.cs
#	src/Umbraco.Web.UI.NetCore/appsettings.json
#	src/Umbraco.Web/Editors/BackOfficeController.cs
#	src/Umbraco.Web/Runtime/WebInitialComponent.cs
2020-11-12 13:10:19 +01:00

69 lines
2.4 KiB
C#

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SixLabors.ImageSharp.Web.DependencyInjection;
using Umbraco.Web.BackOffice.Middleware;
using Umbraco.Web.BackOffice.Routing;
namespace Umbraco.Extensions
{
public static class BackOfficeApplicationBuilderExtensions
{
public static IApplicationBuilder UseUmbraco(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
app.UseStatusCodePages();
app.UseRouting();
app.UseUmbracoCore();
app.UseUmbracoRouting();
app.UseRequestLocalization();
app.UseUmbracoRequestLogging();
app.UseUmbracoBackOffice();
app.UseUmbracoPreview();
app.UseUmbracoInstaller();
return app;
}
public static IApplicationBuilder UseUmbracoBackOffice(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
// Important we handle image manipulations before the static files, otherwise the querystring is just ignored.
// TODO: Since we are dependent on these we need to register them but what happens when we call this multiple times since we are dependent on this for UseUmbracoBackOffice too?
app.UseImageSharp();
app.UseStaticFiles();
// Must be called after UseRouting and before UseEndpoints
app.UseSession();
if (!app.UmbracoCanBoot()) return app;
app.UseEndpoints(endpoints =>
{
var backOfficeRoutes = app.ApplicationServices.GetRequiredService<BackOfficeAreaRoutes>();
backOfficeRoutes.CreateRoutes(endpoints);
});
app.UseUmbracoRuntimeMinification();
app.UseMiddleware<PreviewAuthenticationMiddleware>();
app.UseMiddleware<BackOfficeExternalLoginProviderErrorMiddleware>();
return app;
}
public static IApplicationBuilder UseUmbracoPreview(this IApplicationBuilder app)
{
app.UseEndpoints(endpoints =>
{
var previewRoutes = app.ApplicationServices.GetRequiredService<PreviewRoutes>();
previewRoutes.CreateRoutes(endpoints);
});
return app;
}
}
}