diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index 443d7c33..a7239af2 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -201,9 +201,12 @@ namespace Microsoft.Extensions.DependencyInjection // set the cookies to allow HttpClient API calls to be authenticated var httpContextAccessor = s.GetRequiredService(); - foreach (var cookie in httpContextAccessor.HttpContext.Request.Cookies) + if (httpContextAccessor.HttpContext != null) { - client.DefaultRequestHeaders.Add("Cookie", cookie.Key + "=" + cookie.Value); + foreach (var cookie in httpContextAccessor.HttpContext.Request.Cookies) + { + client.DefaultRequestHeaders.Add("Cookie", cookie.Key + "=" + cookie.Value); + } } return client;