Skip to content

Commit e67da0b

Browse files
author
Paul Johnson
authored
Ignore certificate errors for KeepAlive task. (#12019)
1 parent 4f0a837 commit e67da0b

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Umbraco.Cms.Core
2+
{
3+
/// <summary>
4+
/// Defines constants.
5+
/// </summary>
6+
public static partial class Constants
7+
{
8+
/// <summary>
9+
/// Defines constants for named http clients.
10+
/// </summary>
11+
public static class HttpClients
12+
{
13+
/// <summary>
14+
/// Name for http client which ignores certificate errors.
15+
/// </summary>
16+
public const string IgnoreCertificateErrors = "Umbraco:HttpClients:IgnoreCertificateErrors";
17+
}
18+
}
19+
}

src/Umbraco.Infrastructure/HostedServices/KeepAlive.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.Extensions.Logging;
99
using Microsoft.Extensions.Options;
10+
using Umbraco.Cms.Core;
1011
using Umbraco.Cms.Core.Configuration.Models;
1112
using Umbraco.Cms.Core.Hosting;
1213
using Umbraco.Cms.Core.Logging;
@@ -99,7 +100,7 @@ public override async Task PerformExecuteAsync(object state)
99100
try
100101
{
101102
var request = new HttpRequestMessage(HttpMethod.Get, keepAlivePingUrl);
102-
HttpClient httpClient = _httpClientFactory.CreateClient();
103+
HttpClient httpClient = _httpClientFactory.CreateClient(Constants.HttpClients.IgnoreCertificateErrors);
103104
_ = await httpClient.SendAsync(request);
104105
}
105106
catch (Exception ex)

src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Data.SqlClient;
44
using System.IO;
55
using System.Linq;
6+
using System.Net.Http;
67
using System.Reflection;
78
using Dazinator.Extensions.FileProviders.GlobPatternFilter;
89
using Microsoft.AspNetCore.Builder;
@@ -191,6 +192,11 @@ public static IUmbracoBuilder AddHostedServices(this IUmbracoBuilder builder)
191192
private static IUmbracoBuilder AddHttpClients(this IUmbracoBuilder builder)
192193
{
193194
builder.Services.AddHttpClient();
195+
builder.Services.AddHttpClient(Constants.HttpClients.IgnoreCertificateErrors)
196+
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
197+
{
198+
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
199+
});
194200
return builder;
195201
}
196202

0 commit comments

Comments
 (0)