Context 关键字在 ASP.net 5 MVC Controller 中无法识别以用于会话

Context keyword doesn't get recognized in ASP.net 5 MVC Controller for use with Sessions

我正在使用 ASP.net 5 Beta 8。我想使用会话,但是上下文关键字不被理解。

在我的packages.json

"Microsoft.AspNet.Http": "1.0.0-beta8",
"Microsoft.AspNet.Session": "1.0.0-beta8",

在我的Startup.cs

的ConfigureServices
 // Add MVC services to the services container.
 services.AddMvc();

 //Session Support
 services.AddSession();
 services.AddCaching();

在 Startup.cs

的配置中
        //Session
        app.UseSession();

        // Add MVC to the request pipeline.
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
      });

在HomeController.cs

using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Session;
using Microsoft.AspNet.Http;


public IActionResult Index()
{
    Context.Session.SetString("MyString", "test");
    return View();
}

我得到的错误是

The name 'Context' does not exist in the current context

我还尝试从 project.json

中删除 dnx 核心
"frameworks": {
   "dnx451": { }
 },

但它也不起作用。

请注意:我已使用之前关于 Whosebug 的答案尝试解决问题,但没有奏效。例如

我也在 ASP.NET 5 中尝试了关于 Sessions 的各种博客文章,但我仍然遇到同样的错误。

解决方案是使用 HttpContext

 HttpContext.Session.SetString("MyString", "test");

对 beta 8 进行了一些重命名,这里有一个有用的 link

Older                               Beta 8
Context                             HttpContext
Context.Session.Set(String, byte[]) HttpContext.Session.SetInt32(String, byte[])

诊断 诊断程序提供的错误页面具有更好的名称以避免混淆。

app.UseDeveloperExceptionPage();

Older                  Beta 8
app.ErrorHandler()     app.UseExceptionHandler()
app.ErrorPage()        app.UseDeveloperExceptionPage()