diff --git a/src/Umbraco.Web/HealthCheck/Checks/Config/TrySkipIisCustomErrorsCheck.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/TrySkipIisCustomErrorsCheck.cs similarity index 78% rename from src/Umbraco.Web/HealthCheck/Checks/Config/TrySkipIisCustomErrorsCheck.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/TrySkipIisCustomErrorsCheck.cs index 6cfbf18370..58172ba063 100644 --- a/src/Umbraco.Web/HealthCheck/Checks/Config/TrySkipIisCustomErrorsCheck.cs +++ b/src/Umbraco.Abstractions/Configuration/HealthChecks/TrySkipIisCustomErrorsCheck.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.Services; namespace Umbraco.Web.HealthCheck.Checks.Config @@ -12,11 +13,14 @@ namespace Umbraco.Web.HealthCheck.Checks.Config Group = "Configuration")] public class TrySkipIisCustomErrorsCheck : AbstractConfigCheck { - private readonly Version _serverVersion = HttpRuntime.IISVersion; + private readonly IHostingEnvironment _hostingEnvironment; - public TrySkipIisCustomErrorsCheck(ILocalizedTextService textService, IIOHelper ioHelper) - : base(textService, ioHelper) - { } + public TrySkipIisCustomErrorsCheck(ILocalizedTextService textService, IIOHelper ioHelper, ILogger logger, + IHostingEnvironment hostingEnvironment) + : base(textService, ioHelper, logger) + { + _hostingEnvironment = hostingEnvironment; + } public override string FilePath => "~/Config/umbracoSettings.config"; @@ -29,7 +33,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Config get { // beware! 7.5 and 7.5.0 are not the same thing! - var recommendedValue = _serverVersion >= new Version("7.5") + var recommendedValue = _hostingEnvironment.IISVersion >= new Version("7.5") ? bool.TrueString.ToLower() : bool.FalseString.ToLower(); return new List { new AcceptableConfiguration { IsRecommended = true, Value = recommendedValue } }; @@ -41,7 +45,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Config get { return TextService.Localize("healthcheck/trySkipIisCustomErrorsCheckSuccessMessage", - new[] { Values.First(v => v.IsRecommended).Value, _serverVersion.ToString() }); + new[] { Values.First(v => v.IsRecommended).Value, _hostingEnvironment.IISVersion.ToString() }); } } @@ -50,7 +54,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Config get { return TextService.Localize("healthcheck/trySkipIisCustomErrorsCheckErrorMessage", - new[] { CurrentValue, Values.First(v => v.IsRecommended).Value, _serverVersion.ToString() }); + new[] { CurrentValue, Values.First(v => v.IsRecommended).Value, _hostingEnvironment.IISVersion.ToString() }); } } @@ -59,7 +63,7 @@ namespace Umbraco.Web.HealthCheck.Checks.Config get { return TextService.Localize("healthcheck/trySkipIisCustomErrorsCheckRectifySuccessMessage", - new[] { Values.First(v => v.IsRecommended).Value, _serverVersion.ToString() }); + new[] { Values.First(v => v.IsRecommended).Value, _hostingEnvironment.IISVersion.ToString() }); } } } diff --git a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs index cf2667c121..1662879cf2 100644 --- a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs @@ -1,3 +1,5 @@ +using System; + namespace Umbraco.Core.Hosting { public interface IHostingEnvironment @@ -16,6 +18,7 @@ namespace Umbraco.Core.Hosting /// Gets a value indicating whether Umbraco is hosted. /// bool IsHosted { get; } + Version IISVersion { get; } string MapPath(string path); string ToAbsolute(string virtualPath, string root); diff --git a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs index c9336546c5..f9b1f1019b 100644 --- a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs @@ -27,6 +27,7 @@ namespace Umbraco.Web.Hosting ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath; ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; CurrentDomainId = AppDomain.CurrentDomain.Id; + IISVersion = HttpRuntime.IISVersion; } public int CurrentDomainId { get; } @@ -39,6 +40,9 @@ namespace Umbraco.Web.Hosting public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.DebugMode; /// public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted); + + public Version IISVersion { get; } + public string MapPath(string path) { return HostingEnvironment.MapPath(path);