2016-06-13 17:42:05 +02:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
2020-09-21 13:04:57 +02:00
using Microsoft.Extensions.Logging ;
2020-10-21 10:29:25 +01:00
using Microsoft.Extensions.Options ;
using Umbraco.Core.Configuration.Models ;
2020-01-28 13:41:54 +01:00
using Umbraco.Core.Hosting ;
2016-06-13 17:42:05 +02:00
using Umbraco.Core.Services ;
2020-10-21 10:29:25 +01:00
namespace Umbraco.Core.HealthCheck.Checks.Configuration
2016-06-13 17:42:05 +02:00
{
2020-10-21 10:29:25 +01:00
[Obsolete("This is not currently in the appsettings.JSON and so can either be removed, or rewritten in .NET Core fashion")]
2016-06-13 17:42:05 +02:00
[ HealthCheck ( "046A066C-4FB2-4937-B931-069964E16C66" , "Try Skip IIS Custom Errors" ,
Description = "Starting with IIS 7.5, this must be set to true for Umbraco 404 pages to show. Otherwise, IIS will takeover and render its built-in error page." ,
Group = "Configuration" ) ]
2020-10-21 10:29:25 +01:00
public class TrySkipIisCustomErrorsCheck : AbstractSettingsCheck
2016-06-13 17:42:05 +02:00
{
2020-10-21 10:29:25 +01:00
private readonly ILocalizedTextService _textService ;
private readonly ILoggerFactory _loggerFactory ;
2020-02-25 09:45:56 +01:00
private readonly Version _iisVersion ;
2020-10-21 10:29:25 +01:00
private readonly GlobalSettings _globalSettings ;
2016-06-13 17:42:05 +02:00
2020-10-21 10:29:25 +01:00
public TrySkipIisCustomErrorsCheck ( ILocalizedTextService textService , ILoggerFactory loggerFactory , IOptions < GlobalSettings > globalSettings )
: base ( textService , loggerFactory )
2020-01-28 13:41:54 +01:00
{
2020-10-21 10:29:25 +01:00
_textService = textService ;
_loggerFactory = loggerFactory ;
//TODO: detect if hosted in IIS, and then IIS version if we want to go this route
_iisVersion = new Version ( "7.5" ) ;
_globalSettings = globalSettings . Value ;
2020-01-28 13:41:54 +01:00
}
2016-06-13 17:42:05 +02:00
2020-10-21 10:29:25 +01:00
public override string ItemPath = > "TBC" ;
2016-06-13 17:42:05 +02:00
2016-09-01 19:06:08 +02:00
public override ValueComparisonType ValueComparisonType = > ValueComparisonType . ShouldEqual ;
2016-06-13 17:42:05 +02:00
2020-10-21 10:29:25 +01:00
public override string CurrentValue = > null ;
2016-06-13 17:42:05 +02:00
public override IEnumerable < AcceptableConfiguration > Values
{
get
{
2016-10-26 14:24:31 +02:00
// beware! 7.5 and 7.5.0 are not the same thing!
2020-02-25 09:45:56 +01:00
var recommendedValue = _iisVersion > = new Version ( "7.5" )
2016-06-13 17:42:05 +02:00
? bool . TrueString . ToLower ( )
: bool . FalseString . ToLower ( ) ;
2020-10-21 10:29:25 +01:00
return new List < AcceptableConfiguration > { new AcceptableConfiguration { IsRecommended = true , Value = recommendedValue } } ;
2016-06-13 17:42:05 +02:00
}
}
public override string CheckSuccessMessage
{
get
{
2020-10-21 10:29:25 +01:00
return _textService . Localize ( "healthcheck/trySkipIisCustomErrorsCheckSuccessMessage" ,
2020-02-25 09:45:56 +01:00
new [ ] { Values . First ( v = > v . IsRecommended ) . Value , _iisVersion . ToString ( ) } ) ;
2016-06-13 17:42:05 +02:00
}
}
public override string CheckErrorMessage
{
get
{
2020-10-21 10:29:25 +01:00
return _textService . Localize ( "healthcheck/trySkipIisCustomErrorsCheckErrorMessage" ,
2020-02-25 09:45:56 +01:00
new [ ] { CurrentValue , Values . First ( v = > v . IsRecommended ) . Value , _iisVersion . ToString ( ) } ) ;
2016-06-13 17:42:05 +02:00
}
}
public override string RectifySuccessMessage
{
get
{
2020-10-21 10:29:25 +01:00
return _textService . Localize ( "healthcheck/trySkipIisCustomErrorsCheckRectifySuccessMessage" ,
new [ ] { "Not implemented" } ) ;
//new[] { Values.First(v => v.IsRecommended).Value, _iisVersion.ToString() });
2016-06-13 17:42:05 +02:00
}
}
}
2017-07-20 11:21:28 +02:00
}