diff --git a/src/Umbraco.Core/WebAssets/IRuntimeMinifier.cs b/src/Umbraco.Core/WebAssets/IRuntimeMinifier.cs index 03f6b179ff..2b68a2f4ec 100644 --- a/src/Umbraco.Core/WebAssets/IRuntimeMinifier.cs +++ b/src/Umbraco.Core/WebAssets/IRuntimeMinifier.cs @@ -34,7 +34,7 @@ namespace Umbraco.Core.WebAssets /// /// An html encoded string /// - string RenderCssHere(string bundleName); + Task RenderCssHereAsync(string bundleName); /// /// Creates a JS bundle @@ -56,7 +56,7 @@ namespace Umbraco.Core.WebAssets /// /// An html encoded string /// - string RenderJsHere(string bundleName); + Task RenderJsHereAsync(string bundleName); /// /// Returns the asset paths for the bundle name diff --git a/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs b/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs deleted file mode 100644 index db5c7a8510..0000000000 --- a/src/Umbraco.Web.BackOffice/ActionResults/JsonNetResult.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; - -namespace Umbraco.Web.BackOffice.ActionResults -{ - /// - /// Custom json result using newtonsoft json.net - /// - public class JsonNetResult : IActionResult - { - public Encoding ContentEncoding { get; set; } - public string ContentType { get; set; } - public object Data { get; set; } - - public JsonSerializerSettings SerializerSettings { get; set; } - public Formatting Formatting { get; set; } - - public JsonNetResult() - { - SerializerSettings = new JsonSerializerSettings(); - } - - public Task ExecuteResultAsync(ActionContext context) - { - if (context is null) - throw new ArgumentNullException(nameof(context)); - - var response = context.HttpContext.Response; - - response.ContentType = string.IsNullOrEmpty(ContentType) == false - ? ContentType - : System.Net.Mime.MediaTypeNames.Application.Json; - - if (!(ContentEncoding is null)) - response.Headers.Add(Microsoft.Net.Http.Headers.HeaderNames.ContentEncoding, ContentEncoding.ToString()); - - if (!(Data is null)) - { - using var bodyWriter = new StreamWriter(response.Body); - using var writer = new JsonTextWriter(bodyWriter) { Formatting = Formatting }; - var serializer = JsonSerializer.Create(SerializerSettings); - serializer.Serialize(writer, Data); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index aecad8c4e4..e7e817f649 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -1,11 +1,11 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.BackOffice; using Umbraco.Core.Cache; @@ -15,8 +15,6 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Services; using Umbraco.Core.WebAssets; using Umbraco.Extensions; -using Umbraco.Net; -using Umbraco.Web.BackOffice.ActionResults; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.ActionResults; using Umbraco.Web.Models; @@ -93,7 +91,7 @@ namespace Umbraco.Web.BackOffice.Controllers /// /// [HttpGet] - public JsonNetResult LocalizedText(string culture = null) + public Dictionary> LocalizedText(string culture = null) { var securityHelper = _umbracoContextAccessor.GetRequiredUmbracoContext().Security; var isAuthenticated = securityHelper.IsAuthenticated(); @@ -125,14 +123,14 @@ namespace Umbraco.Web.BackOffice.Controllers .ToDictionary(pv => pv.Key, pv => pv.ToDictionary(pve => pve.valueAlias, pve => pve.value)); - return new JsonNetResult { Data = nestedDictionary, Formatting = Formatting.None }; + return nestedDictionary; } [UmbracoAuthorize(Order = 0)] [HttpGet] - public JsonNetResult GetGridConfig() + public IEnumerable GetGridConfig() { - return new JsonNetResult { Data = _gridConfig.EditorsConfig.Editors, Formatting = Formatting.None }; + return _gridConfig.EditorsConfig.Editors; } /// @@ -156,7 +154,7 @@ namespace Umbraco.Web.BackOffice.Controllers } [HttpGet] - public async Task ValidatePasswordResetCode([Bind(Prefix = "u")]int userId, [Bind(Prefix = "r")]string resetCode) + public async Task ValidatePasswordResetCode([Bind(Prefix = "u")]int userId, [Bind(Prefix = "r")]string resetCode) { var user = await _userManager.FindByIdAsync(userId.ToString()); if (user != null) @@ -180,9 +178,9 @@ namespace Umbraco.Web.BackOffice.Controllers /// otherwise process the external login info. /// /// - private async Task RenderDefaultOrProcessExternalLoginAsync( - Func defaultResponse, - Func externalSignInResponse) + private async Task RenderDefaultOrProcessExternalLoginAsync( + Func defaultResponse, + Func externalSignInResponse) { if (defaultResponse is null) throw new ArgumentNullException(nameof(defaultResponse)); if (externalSignInResponse is null) throw new ArgumentNullException(nameof(externalSignInResponse)); @@ -213,7 +211,7 @@ namespace Umbraco.Web.BackOffice.Controllers // Used for XSRF protection when adding external logins private const string XsrfKey = "XsrfId"; - private ActionResult RedirectToLocal(string returnUrl) + private IActionResult RedirectToLocal(string returnUrl) { if (Url.IsLocalUrl(returnUrl)) { diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index 051193c290..e97ee0d1e5 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -48,6 +48,7 @@ namespace Umbraco.Web.BackOffice.Controllers IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, + IHttpContextAccessor httpContextAccessor, //TreeCollection treeCollection, // TODO: If we need this we need to migrate trees IHostingEnvironment hostingEnvironment, IRuntimeSettings settings, @@ -62,6 +63,7 @@ namespace Umbraco.Web.BackOffice.Controllers _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); + _httpContextAccessor = httpContextAccessor; //_treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection)); _hostingEnvironment = hostingEnvironment; _settings = settings; diff --git a/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/HtmlHelperBackOfficeExtensions.cs similarity index 66% rename from src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs rename to src/Umbraco.Web.BackOffice/Extensions/HtmlHelperBackOfficeExtensions.cs index bf1ad35bec..894ab5f5f6 100644 --- a/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/HtmlHelperBackOfficeExtensions.cs @@ -1,36 +1,32 @@ -using System.Collections.Generic; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Routing; +using Newtonsoft.Json; +using System.Collections.Generic; using System.Linq; using System.Text; -using System.Web; -using System.Web.Mvc; -using Microsoft.Owin.Security; -using Newtonsoft.Json; +using System.Threading.Tasks; +using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Core.Runtime; using Umbraco.Core.WebAssets; -using Umbraco.Web.Composing; -using Umbraco.Web.Editors; +using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Features; using Umbraco.Web.Models; -using Umbraco.Web.Security; -using Umbraco.Web.Trees; +using Umbraco.Web.WebApi; using Umbraco.Web.WebAssets; -namespace Umbraco.Web +namespace Umbraco.Extensions { - /// - /// HtmlHelper extensions for the back office - /// public static class HtmlHelperBackOfficeExtensions { /// /// Outputs a script tag containing the bare minimum (non secure) server vars for use with the angular app /// /// - /// + /// /// /// /// @@ -46,10 +42,9 @@ namespace Umbraco.Web /// These are the bare minimal server variables that are required for the application to start without being authenticated, /// we will load the rest of the server vars after the user is authenticated. /// - public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, TreeCollection treeCollection, IHostingEnvironment hostingEnvironment, IRuntimeSettings settings, ISecuritySettings securitySettings, IRuntimeMinifier runtimeMinifier) + public static async Task BareMinimumServerVariablesScriptAsync(this IHtmlHelper html, BackOfficeServerVariables backOfficeServerVariables) { - var serverVars = new BackOfficeServerVariables(uri, Current.RuntimeState, features, globalSettings, umbracoVersion, contentSettings, treeCollection, hostingEnvironment, settings, securitySettings, runtimeMinifier); - var minVars = serverVars.BareMinimumServerVariables(); + var minVars = await backOfficeServerVariables.BareMinimumServerVariablesAsync(); var str = @" + + + + @if (isDebug) + { + @Html.Raw(profilerHtml.Render()) + } + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 2f70515426..20d6714778 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -261,7 +261,6 @@ - diff --git a/src/Umbraco.Web/UrlHelperExtensions.cs b/src/Umbraco.Web/UrlHelperExtensions.cs index fb775db5c3..3659168577 100644 --- a/src/Umbraco.Web/UrlHelperExtensions.cs +++ b/src/Umbraco.Web/UrlHelperExtensions.cs @@ -115,38 +115,8 @@ namespace Umbraco.Web } - /// - /// Return the Url for an action with a cache-busting hash appended - /// - /// - /// - /// - /// - /// - public static string GetUrlWithCacheBust(this UrlHelper url, string actionName, string controllerName, RouteValueDictionary routeVals = null) - { - var applicationJs = url.Action(actionName, controllerName, routeVals); - applicationJs = applicationJs + "?umb__rnd=" + GetCacheBustHash(); - return applicationJs; - } + - /// - /// - /// - /// - public static string GetCacheBustHash() - { - //make a hash of umbraco and client dependency version - //in case the user bypasses the installer and just bumps the web.config or client dependency config - - //if in debug mode, always burst the cache - if (Current.HostingEnvironment.IsDebugMode) - { - return DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).GenerateHash(); - } - - var version = Current.UmbracoVersion.SemanticVersion.ToSemanticString(); - return $"{version}.{Current.RuntimeMinifier.CacheBuster}".GenerateHash(); - } + } } diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs index cf0e001d3b..0cd03d2ee6 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyRuntimeMinifier.cs @@ -50,11 +50,11 @@ namespace Umbraco.Web.WebAssets.CDF filePaths.Select(x => new CssFile(x)).ToArray()); } - public string RenderCssHere(string bundleName) + public Task RenderCssHereAsync(string bundleName) { var bundleFiles = GetCssBundleFiles(bundleName); - if (bundleFiles == null) return string.Empty; - return RenderOutput(bundleFiles, AssetType.Css); + if (bundleFiles == null) return Task.FromResult(string.Empty); + return Task.FromResult(RenderOutput(bundleFiles, AssetType.Css)); } public void CreateJsBundle(string bundleName, params string[] filePaths) @@ -67,11 +67,11 @@ namespace Umbraco.Web.WebAssets.CDF filePaths.Select(x => new JavascriptFile(x)).ToArray()); } - public string RenderJsHere(string bundleName) + public Task RenderJsHereAsync(string bundleName) { var bundleFiles = GetJsBundleFiles(bundleName); - if (bundleFiles == null) return string.Empty; - return RenderOutput(bundleFiles, AssetType.Javascript); + if (bundleFiles == null) return Task.FromResult(string.Empty); + return Task.FromResult(RenderOutput(bundleFiles, AssetType.Javascript)); } public Task> GetAssetPathsAsync(string bundleName)