zoukankan      html  css  js  c++  java
  • asp.net core中Microsoft.AspNet.Session的使用

    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")

     5、参考

    示例:https://github.com/aspnet/Session/tree/dev/samples/SessionSample

    仓库:https://github.com/aspnet/Session

  • 相关阅读:
    645. Set Mismatch
    400. Nth Digit
    633. Sum of Square Numbers
    507. Perfect Number
    453. Minimum Moves to Equal Array Elements
    441. Arranging Coins
    Girls and Boys
    二分图
    Gap
    SZU-A22
  • 原文地址:https://www.cnblogs.com/zhouXX/p/6037034.html
Copyright © 2011-2022 走看看