Core 父类 Api 访问HttpContext 为NULL

 

新建Helper类

    public static class HelperHttpContext
    {
        public static IServiceCollection serviceCollection;

        public static HttpContext Current
        {
            get
            {
                object factory = serviceCollection.BuildServiceProvider().GetService(typeof(IHttpContextAccessor));
                HttpContext context = ((IHttpContextAccessor)factory).HttpContext;
                return context;
            }
        }
    }

然后再Startup  ConfigServices中 添加以下代码

// 增加Http组件
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
HelperHttpContext.serviceCollection = services; 


Core 父类 Api 访问HttpContext 为NULL

上一篇:WireShark Cmake编译报错FATAL_ERROR "Windows setup (win-setup.ps1) failed


下一篇:js判断是否为ie的方法