Ignore certificate errors for KeepAlive task. (#12019)
This commit is contained in:
19
src/Umbraco.Core/Constants-HttpClients.cs
Normal file
19
src/Umbraco.Core/Constants-HttpClients.cs
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user