Ignore certificate errors for KeepAlive task. (#12019)

This commit is contained in:
Paul Johnson
2022-02-22 08:49:56 +00:00
committed by GitHub
parent 4f0a837e20
commit e67da0b198
3 changed files with 27 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
namespace Umbraco.Cms.Core
{
/// <summary>
/// Defines constants.
/// </summary>
public static partial class Constants
{
/// <summary>
/// Defines constants for named http clients.
/// </summary>
public static class HttpClients
{
/// <summary>
/// Name for http client which ignores certificate errors.
/// </summary>
public const string IgnoreCertificateErrors = "Umbraco:HttpClients:IgnoreCertificateErrors";
}
}
}

View File

@@ -7,6 +7,7 @@ using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Logging;
@@ -99,7 +100,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
try
{
var request = new HttpRequestMessage(HttpMethod.Get, keepAlivePingUrl);
HttpClient httpClient = _httpClientFactory.CreateClient();
HttpClient httpClient = _httpClientFactory.CreateClient(Constants.HttpClients.IgnoreCertificateErrors);
_ = await httpClient.SendAsync(request);
}
catch (Exception ex)

View File

@@ -3,6 +3,7 @@ using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using Dazinator.Extensions.FileProviders.GlobPatternFilter;
using Microsoft.AspNetCore.Builder;
@@ -191,6 +192,11 @@ namespace Umbraco.Extensions
private static IUmbracoBuilder AddHttpClients(this IUmbracoBuilder builder)
{
builder.Services.AddHttpClient();
builder.Services.AddHttpClient(Constants.HttpClients.IgnoreCertificateErrors)
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});
return builder;
}