using Microsoft.Extensions.DependencyInjection; using System.Net.Http; public class Program { public static void Main(string[] args) { var serviceProvider = new ServiceCollection() .AddHttpClient("myclient") .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false }) .BuildServiceProvider(); var clientFactory = serviceProvider.GetRequiredServiceIn this example, we are creating an HttpClient named "myclient" and configuring its primary HttpMessageHandler to be a new instance of HttpClientHandler with the AllowAutoRedirect property set to false. This code utilizes the Microsoft.Extensions.Http package, which is a library that provides a set of HttpClient factory methods and related support infrastructure.(); var client = clientFactory.CreateClient("myclient"); } }