Cannot get HttpContext to work in .Net Core 3.1 Console Application

I want to use HttpContext in my .NET Core 3.1 Console App, but it is always null. This is what my code looks like:

internal class Startup
    public static IHttpContextAccessor _httpContextAccessor;

    internal Startup(IHttpContextAccessor httpContextAccessor)
        _httpContextAccessor = httpContextAccessor;

    public static void ConfigureServices(IServiceCollection services)

    private static void Main(string[] args)
        var serviceCollection = new ServiceCollection();

        var context = _httpContextAccessor.HttpContext;


context is always null. Can anyone offer advice? Thanks

Read more here:

Content Attribution

This content was originally published by Rich at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: