首页 > Windows开发 > 详细

Core 父类 Api 访问HttpContext 为NULL

时间:2021-08-13 10:07:01      阅读:21      评论:0      收藏:0      [点我收藏+]

 

新建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

原文:https://www.cnblogs.com/RecordOnLog/p/15135949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!