asp.net core中Microsoft.AspNet.Session的使用

Original 2016-11-08 11:31:01 568
abstract:1、通过nuget/修改project.json引用  2、引用存储session的媒介,如内存、数据库、redis等 "Microsoft.AspNetCore.Session": "1.1.0-*",     "Microsoft.Extensions.Cachi

1、通过nuget/修改project.json引用  

2、引用存储session的媒介,如内存、数据库、redis等

 "Microsoft.AspNetCore.Session": "1.1.0-*",

    "Microsoft.Extensions.Caching.Memory": "1.1.0-*",

    "Microsoft.Extensions.Caching.Redis": "1.1.0-*",

    "Microsoft.Extensions.Caching.SqlServer": "1.1.0-*",

3、修改startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddMvc();
        }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseSession();

4、使用

Context.Session.GetString("UserName")


Release Notes

Popular Entries