2016-09-01 11:25:00 +02:00
|
|
|
|
using System;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
using System.Configuration;
|
2018-03-27 10:04:07 +02:00
|
|
|
|
using System.IO;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web.Configuration;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using System.Web.Http;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using System.Web.Http.Dispatcher;
|
|
|
|
|
|
using System.Web.Mvc;
|
2018-03-27 10:04:07 +02:00
|
|
|
|
using ClientDependency.Core.CompositeFiles.Providers;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using ClientDependency.Core.Config;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core;
|
2017-05-30 15:46:25 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
2017-12-28 09:27:57 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2019-01-15 22:08:08 +11:00
|
|
|
|
using Umbraco.Core.IO;
|
2019-01-29 23:05:59 +11:00
|
|
|
|
using Umbraco.Web.JavaScript;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Web.WebApi;
|
2018-10-29 17:27:33 +11:00
|
|
|
|
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Current = Umbraco.Web.Composing.Current;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2017-12-28 09:27:57 +01:00
|
|
|
|
namespace Umbraco.Web.Runtime
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
2019-03-05 08:47:31 +01:00
|
|
|
|
public sealed class WebInitialComponent : IComponent
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
2019-01-07 09:30:47 +01:00
|
|
|
|
private readonly IGlobalSettings _globalSettings;
|
|
|
|
|
|
|
2019-03-11 13:14:32 +01:00
|
|
|
|
public WebInitialComponent(IGlobalSettings globalSettings)
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
2019-01-07 09:30:47 +01:00
|
|
|
|
_globalSettings = globalSettings;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
2019-02-14 12:11:06 +01:00
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
// setup mvc and webapi services
|
|
|
|
|
|
SetupMvcAndWebApi();
|
|
|
|
|
|
|
2019-02-15 16:41:50 +11:00
|
|
|
|
// When using a non-web runtime and this component is loaded ClientDependency explodes because it'll
|
|
|
|
|
|
// want to access HttpContext.Current, which doesn't exist
|
|
|
|
|
|
if (IOHelper.IsHosted)
|
|
|
|
|
|
{
|
|
|
|
|
|
ConfigureClientDependency(_globalSettings);
|
|
|
|
|
|
}
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
|
|
|
|
|
// Disable the X-AspNetMvc-Version HTTP Header
|
|
|
|
|
|
MvcHandler.DisableMvcResponseHeader = true;
|
|
|
|
|
|
|
|
|
|
|
|
// wrap view engines in the profiling engine
|
|
|
|
|
|
WrapViewEngines(ViewEngines.Engines);
|
|
|
|
|
|
|
|
|
|
|
|
// add global filters
|
|
|
|
|
|
ConfigureGlobalFilters();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-07 09:30:47 +01:00
|
|
|
|
public void Terminate()
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private static void ConfigureGlobalFilters()
|
|
|
|
|
|
{
|
|
|
|
|
|
GlobalFilters.Filters.Add(new EnsurePartialViewMacroViewContextFilterAttribute());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// internal for tests
|
|
|
|
|
|
internal static void WrapViewEngines(IList<IViewEngine> viewEngines)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (viewEngines == null || viewEngines.Count == 0) return;
|
|
|
|
|
|
|
2018-12-12 14:28:57 +01:00
|
|
|
|
var originalEngines = viewEngines.ToList();
|
2016-09-01 19:06:08 +02:00
|
|
|
|
viewEngines.Clear();
|
|
|
|
|
|
foreach (var engine in originalEngines)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine);
|
|
|
|
|
|
viewEngines.Add(wrappedEngine);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void SetupMvcAndWebApi()
|
|
|
|
|
|
{
|
|
|
|
|
|
//don't output the MVC version header (security)
|
|
|
|
|
|
MvcHandler.DisableMvcResponseHeader = true;
|
|
|
|
|
|
|
|
|
|
|
|
// set master controller factory
|
|
|
|
|
|
var controllerFactory = new MasterControllerFactory(() => Current.FilteredControllerFactories);
|
|
|
|
|
|
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
|
|
|
|
|
|
|
|
|
|
|
|
// set the render & plugin view engines
|
|
|
|
|
|
ViewEngines.Engines.Add(new RenderViewEngine());
|
|
|
|
|
|
ViewEngines.Engines.Add(new PluginViewEngine());
|
|
|
|
|
|
|
|
|
|
|
|
//set model binder
|
2018-03-27 10:04:07 +02:00
|
|
|
|
ModelBinderProviders.BinderProviders.Add(ContentModelBinder.Instance); // is a provider
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
|
|
|
|
|
////add the profiling action filter
|
|
|
|
|
|
//GlobalFilters.Filters.Add(new ProfilingActionFilter());
|
|
|
|
|
|
|
|
|
|
|
|
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
|
|
|
|
|
|
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
2016-09-01 11:25:00 +02:00
|
|
|
|
}
|
2018-03-27 10:04:07 +02:00
|
|
|
|
|
2018-04-06 13:51:54 +10:00
|
|
|
|
private static void ConfigureClientDependency(IGlobalSettings globalSettings)
|
2018-03-27 10:04:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
// Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK]
|
2019-01-15 22:08:08 +11:00
|
|
|
|
XmlFileMapper.FileMapDefaultFolder = SystemDirectories.TempData.EnsureEndsWith('/') + "ClientDependency";
|
2018-03-27 10:04:07 +02:00
|
|
|
|
BaseCompositeFileProcessingProvider.UrlTypeDefault = CompositeUrlType.Base64QueryStrings;
|
|
|
|
|
|
|
2019-01-31 12:05:56 +00:00
|
|
|
|
// Now we need to detect if we are running 'Umbraco.Core.LocalTempStorage' as EnvironmentTemp and in that case we want to change the CDF file
|
2018-03-27 10:04:07 +02:00
|
|
|
|
// location to be there
|
2018-04-06 13:51:54 +10:00
|
|
|
|
if (globalSettings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp)
|
2018-03-27 10:04:07 +02:00
|
|
|
|
{
|
2019-02-15 08:46:57 +01:00
|
|
|
|
var cachePath = globalSettings.LocalTempPath;
|
2018-05-02 13:38:45 +02:00
|
|
|
|
|
2018-03-27 10:04:07 +02:00
|
|
|
|
//set the file map and composite file default location to the %temp% location
|
|
|
|
|
|
BaseCompositeFileProcessingProvider.CompositeFilePathDefaultFolder
|
|
|
|
|
|
= XmlFileMapper.FileMapDefaultFolder
|
|
|
|
|
|
= Path.Combine(cachePath, "ClientDependency");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigurationManager.GetSection("system.web/httpRuntime") is HttpRuntimeSection section)
|
|
|
|
|
|
{
|
|
|
|
|
|
//set the max url length for CDF to be the smallest of the max query length, max request length
|
|
|
|
|
|
ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(section.MaxQueryStringLength, section.MaxRequestLength);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Register a custom renderer - used to process property editor dependencies
|
|
|
|
|
|
var renderer = new DependencyPathRenderer();
|
|
|
|
|
|
renderer.Initialize("Umbraco.DependencyPathRenderer", new NameValueCollection
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "compositeFileHandlerPath", ClientDependencySettings.Instance.CompositeFileHandlerPath }
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-02-15 16:41:50 +11:00
|
|
|
|
ClientDependencySettings.Instance.MvcRendererCollection.Add(renderer);
|
2018-03-27 10:04:07 +02:00
|
|
|
|
}
|
2016-09-01 11:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|