Angular2项目中的HttpContext为null

时间:2018-04-24 04:28:23

标签: asp.net-mvc angular session

我需要在我的Controller中的其他库中保留特定对象的状态,但我已经按照一些tutos教授如何在Session中使用HttpContext,但是{{1} }在控制器的构造函数中为null

中间件全部设置完毕:

HttpContext

在这种情况下,我正在尝试最简单的事情:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddDistributedMemoryCache();
        services.AddSession();
        services.AddDbContext<AutoListDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        //(...)

        app.UseStaticFiles();

        app.UseSession();

        app.UseMvc(routes =>
        //(...)
     }

public AddDoorController(AutoListDbContext context) { var building = new Building(context); HttpContext.Session.SetString("building", JsonConvert.SerializeObject(building)); } (继承自HttpContext)为空。我错过了什么?

0 个答案:

没有答案